Repeating table and Web Service - InfoPath Dev
in

InfoPath Dev

Repeating table and Web Service

Last post 03-02-2007 09:15 AM by Greg Collins. 14 replies.
Page 1 of 1 (15 items)
Sort Posts: Previous Next
  • 02-19-2007 03:23 AM

    • maddy
    • Not Ranked
    • Joined on 01-25-2007
    • Posts 15

    Repeating table and Web Service

    Hi everyone,

    I am still understanding InfoPath 2003.

    But as the time is limited to deliver, I do have a question.

    Please consider this as urgent.

    I have a repeating table and in that fields are vendor and vendorproduct.
    If vendor is selected, products related to vendor need to be displayed in VendorProduct drop downb list using web service.

    So I wrote onAfterChange code for Vendor...

    Code:
    function msoxd_my_Vendor::OnAfterChange(eventObj)
    {
    // Write code here to restore the global state.
    var oNode = eventObj.Source;
    var oNodeParent = oNode.parentNode;
    oNodeParent.slectSingleNode("my:VendorProduct").text = "";
    XDocument.UI.Alert(eventObj.Source.text)
    //XDocument.DOM.selectSingleNode("//my:VendorProduct").text = ""
    if (eventObj.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to respond to the changes.
    var nodeDataSource = XDocument.DataObjects.Item("GetVendorProductSchema");
    nodeDataSource.DOM.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-25T07:59:20' xmlns:tns='http://slmt.abc.com' xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:xd='http://schemas.microsoft.com/office/infopath/2003'");
    nodeDataSource.DOM.selectSingleNode("//dfs:myFields//dfs:queryFields//tns:GetVendorProductSchema//tns:strSelectedVendor").text = eventObj.Source.text;
    XDocument.DataObjects.Item("GetVendorProductSchema").Query();
    //oNodeParent.slectSingleNode("//my:VendorProduct").text =
    }

    The above works fine if there is a single row. If I add another row while data entry, the value selected in Vendor Product in row 1 is lost. since the value for vendor is different in row2. it displays products related to row2.

    I hope I made myself clear. if you have any queries on the above, do let me know.

    thanks in advance.
    -maddy
  • 02-19-2007 09:43 AM In reply to

    Re: Repeating table and Web Service

    Your problem is that you are always selecting the first VendorProduct:

    oNodeParent.slectSingleNode("//my:VendorProduct")

    The use of "//" in your XPath says to start at your root node and locate the very first instance of VendorProduct in the DOM.

    What you want to do is select the VendorProduct on the same row that the OnAfterChange occured for Vendor. Since your eventObj already points to the Vendor node on the row in question, you simply need to use a relative path to get to the VendorProduct node, which would be "../my:VendorProduct"

    Good luck!
  • 02-21-2007 05:07 AM In reply to

    • maddy
    • Not Ranked
    • Joined on 01-25-2007
    • Posts 15

    Re: Repeating table and Web Service

    Hi Greg,
    Thanks for the response.

    But still I am facing same problem. When I select value in first row for Venfor Product and add a new row, the value selected in the first row is lost.

    May I know why it is happening?

    Please consider this as urgent.

    Thank you.
  • 02-21-2007 02:02 PM In reply to

    Re: Repeating table and Web Service

    It is probably the code you have under the comment: // Write code here to restore the global state.

    Here you are are clearing the value of VendorProduct on every change.
  • 02-21-2007 11:20 PM In reply to

    • maddy
    • Not Ranked
    • Joined on 01-25-2007
    • Posts 15

    Re: Repeating table and Web Service

    Greg,
    Thanks for taking time to respond.

    Below is the final code which I am using in Vendor OnAfterChange event.
    var oNode = eventObj.Source;
    var oNodeParent = oNode.parentNode;
    if (eventObj.IsUndoRedo)
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }
    var nodeDataSource = XDocument.DataObjects.Item("GetVendorProductSchema");
    nodeDataSource.DOM.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-25T07:59:20' xmlns:tns='http://slmt.abc.com' xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:xd='http://schemas.microsoft.com/office/infopath/2003'");
    nodeDataSource.DOM.selectSingleNode("//dfs:myFields//dfs:queryFields//tns:GetVendorProductSchema//tns:strSelectedVendor").text = eventObj.Source.text;
    XDocument.DataObjects.Item("GetVendorProductSchema").Query();
    oNodeParent.selectSingleNode("../my:VendorProduct").text = XDocument.selectSingleNode("PRODUCT_NAME").text

    Problem is, it populates values for Vendor Product correctly in the first row.
    When we add a new row, immediately, users can see that the values in Vendor Product are lost.
    Based on the selection of Vendor name in 2nd row, Vendor Product values displays for all the rows.
    When I am adding a new row or after selecting Vendor name, I get error in the last line saying 'Object doesn't support this property or method'

    can you please guide me where I am doing the mistake.

    thank you in advance.

  • 02-22-2007 09:22 AM In reply to

    Re: Repeating table and Web Service

    One issue I see is that you need to account for the event operation. Right now you are handling both Delete and Insert operations the same way. You only want to be doing this for the insert operation. This can be fixed by changing the line:

    if (eventObj.IsUndoRedo)

    to:

    if (eventObj.IsUndoRedo || eventObj.Operation != "Insert")


    Aside from that, because you are stating that all rows are affected when the Vendor Product value is cleared, this sounds more like an issue with a RULE rather than code. It sounds like there is a rule somewhere which is setting the VendorProduct value. Rules applied to a repeating field usually affect all such repeating fields... thus if you have 15 rows, a rule that sets the value for repeating "VendorProduct" will affect all 15 "VendorProduct" fields.

    Check to see if you have some rule somewhere setting a value to this field.
  • 02-22-2007 11:53 PM In reply to

    • maddy
    • Not Ranked
    • Joined on 01-25-2007
    • Posts 15

    Re: Repeating table and Web Service

    Thanks Greg.
    I don't have any Rules for Vendor or VendorProduct.

    But for VendorProduct I have List Box entries set to 'Lookup values in a data connection to a database, Web Service.....'
    Data Connection name is "GetVendorProductSchema"
    Entries: /dfs:myFields/dfs:dataFields/tns:GetVendorProductSchemaResponse/tns:GetVendorProductSchemaResult/NewDataSet/Table/PRODUCT_NAME
    value: .
    Display Name: .

    And the code for Vendor on After Change event.. including your suggestion:
    function msoxd_my_Vendor::OnAfterChange(eventObj)
    {
    // Write code here to restore the global state.
    var oNode = eventObj.Source;
    var oNodeParent = oNode.parentNode;
    if (eventObj.IsUndoRedo || eventObj.Operation != "Insert")
    {
    // An undo or redo operation has occurred and the DOM is read-only.
    return;
    }

    // A field change has occurred and the DOM is writable. Write code here to respond to the changes.
    var nodeDataSource = XDocument.DataObjects.Item("GetVendorProductSchema");
    nodeDataSource.DOM.setProperty("SelectionNamespaces", "xmlns:my='http://schemas.microsoft.com/office/infopath/2003/myXSD/2007-01-25T07:59:20' xmlns:tns='http://slmt.abc.com' xmlns:dfs='http://schemas.microsoft.com/office/infopath/2003/dataFormSolution' xmlns:xd='http://schemas.microsoft.com/office/infopath/2003'");
    nodeDataSource.DOM.selectSingleNode("//dfs:myFields//dfs:queryFields//tns:GetVendorProductSchema//tns:strSelectedVendor").text = eventObj.Source.text;
    XDocument.DataObjects.Item("GetVendorProductSchema").Query();
    }

    Please advice as I need to finish this task asap. If it is a limitation of InfoPath, please do let me know.

    thank you.

    with rgds,
    Maddy.

  • 02-23-2007 09:19 AM In reply to

    Re: Repeating table and Web Service

    Okay - it all just became clear to me...

    You have your VendorProduct control bound to the Web service. That's not necessarily a problem, but it is in how you are using the Web service, because in the OnAfterChange event handler, you are requerying the Web service every time. This requery causes all the data returned in the dataFields group to be changed -- thus affecting all other rows. Does this make sense?

    So, just how much data do you have in this VendorProductSchema? More than 1000 rows worth? If not, you should just query to get all the data back, and then use a filter on the drop-down to show only the products for the selected vendor. This would solve the issue. Even up to 2000 to 3000 rows it might still be better to query once onload and use filters than to try to come up with an alternate solution.
  • 02-25-2007 09:32 PM In reply to

    • maddy
    • Not Ranked
    • Joined on 01-25-2007
    • Posts 15

    Re: Repeating table and Web Service

    Thanks Greg. That's exactly I am looking at.

    VendorProductSchema may be having 1000-2000 rows. According to your suggestion, in the onLoad event of the form, I should be getting all the vendorProduct details and store it in a separate field.
    if the above is what you suggested, then how we will distinguish which VendorProduct is related to a particular vendor?
    Greg,is there any sample form/code which I can take as reference? I am completly new to InfoPath and not sure where to look.

    Thank you,
    with rgds,
    Maddy
  • 02-26-2007 10:39 AM In reply to

    Re: Repeating table and Web Service

    The relation occurs in your form... i.e. the user picks a vendor, and then picks a related vendor product. Both those values are stored in the form.

    You must have a relationship defined in your data connection or you'd never get this working anyway. I.e. for every vendorproduct returned from your data connection, there needs to be an associated vendor. I am assuming that this is already the case. If not then that should be corrected -- how else would you know which product goes to which vendor?
  • 02-27-2007 06:02 AM In reply to

    • maddy
    • Not Ranked
    • Joined on 01-25-2007
    • Posts 15

    Re: Repeating table and Web Service

    Greg,
    Below is the scenario:

    I have Master/Detail control.
    In that I have Vendor and VendorProduct fields.
    By default VendorProduct is disabled as the user didn't selected any Vendor.

    Now, users selects one of the Vendor Name from a drop down. This Vendor field has onAfterChange code to trigger VendorProduct Web Service.
    For the first row, there is no problem. Once the users add another row, then it looses value in VendorProduct field. I agree we are refreshing all of the fields while adding and the Web Service is updating the VendorProduct field and not the particular row.

    Any ideas?
    thank you.
  • 02-27-2007 10:05 AM In reply to

    Re: Repeating table and Web Service

    What is the data structure returned by the Web service? What it should be returning (at a minimum) is something like this (though the following is strictly an illustration and will not represent your actual structure returned):

    <VendorProducts>
      <VendorProduct vendor="Vendor1" product="Product1"/>
      <VendorProduct vendor="Vendor1" product="Product2"/>
      <VendorProduct vendor="Vendor2" product="Product1"/>
      <VendorProduct vendor="Vendor3" product="Product1"/>
      <VendorProduct vendor="Vendor3" product="Product2"/>
    </VendorProducts>

    If your Web service returns a list where each row contains both a vendor and a product... then you should be able to query once onload. Then your vendor drop-down shows a unique list of vendors (from the WS), and the product drop-down filters for products based on the selected vendor.
  • 02-27-2007 11:21 PM In reply to

    • maddy
    • Not Ranked
    • Joined on 01-25-2007
    • Posts 15

    Re: Repeating table and Web Service

    Greg,
    I think it is not the way I am doing.
    Check the following structure:
    <my:group6>
    <my:VendorDetail>
    <my:Vendor>Quest</my:Vendor>
    <my:VendorProduct>SQL</my:VendorProduct>
    <my:ProductRelease>89</my:ProductRelease>
    <my:Platform>VOS</my:Platform>
    </my:VendorDetail>
    </my:group6>

    It's like a data lookup. I am sure this is not the way I should be implementing. I should be missing something...
    thanks
  • 02-28-2007 05:45 AM In reply to

    • maddy
    • Not Ranked
    • Joined on 01-25-2007
    • Posts 15

    Re: Repeating table and Web Service

    In onLoad I am populating values Vendor and Vendor Product details.
    I tired using Filters on Vendor Product. But it seems while adding second row, it concatenates the selection made in row2 and updates all the values in row1 and row2.

    May I know how to refresh only that particular row and not to update all the row values?

    thank you for responding.
  • 03-02-2007 09:15 AM In reply to

    Re: Repeating table and Web Service

    The schema you showed above looks like your main DOM schema... what does the schema returned from your Web service look like? The example I gave above was just to demonstrate that the Web service schema must have some kind of association between the vendor product and a particular vendor.
Page 1 of 1 (15 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.