Populating a combobox in a repeating table with different values for each row returned by a webservice - InfoPath Dev
in

InfoPath Dev

Populating a combobox in a repeating table with different values for each row returned by a webservice

Last post 02-19-2009 08:21 AM by asestier. 1 replies.
Page 1 of 1 (2 items)
Sort Posts: Previous Next
  • 02-18-2009 08:13 AM

    Populating a combobox in a repeating table with different values for each row returned by a webservice

    Hello,

    I have a repeating table containing a text box and a combobox.

    What i want : user enters value in text box, web service returns values according to value in text box, and combobox is filled with values returned by web service.

    It works fine for the first row, by linking data of my combobox to the web service (configured into Data properties). The problem is that, when there are several rows, all comboxes are updated with the last values returned by web service (and not only the one in the same row).

    I found a lot of things in InfopathDev around this problem, but i can't find a response to my problem (or maybe i don't understand it).

    Can i do what i want without code?

    I think it's not possible, so i try to achieve it by code, and want to add items in combobox programmatically.

    Once again, i found a lot of example, but can't make it works : UI never displays the node i add. But if i save the form as XML, i found them.

     Here's my code, launched in OnBeforeChange event of the text box:

     function insertChildsFromService(psService) {
        XDocument.UI.Alert("insertChildsFromService");
        var index;

        // get results from service
        var theDataObject = XDocument.DataObjects.Item(psService);
        theDataObject.DOM.setProperty("SelectionNamespaces",
                                      'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" ' +
                                      'xmlns:ns="..."');
        var nodesService = theDataObject.DOM.selectNodes("/dfs:myFields/dfs:dataFields/ns:getValuesResponse");
        
        // get parent to modify
        var nodeParent = XDocument.DOM.selectSingleNode("/ns2:documentum/documentum:fields/documentum:doc_child_lda");
        var nodeOption = XDocument.DOM.selectSingleNode("/ns2:documentum/documentum:fields/documentum:doc_child_lda/documentum:child_c_language");
        
        XDocument.View.DisableAutoUpdate();
        if (nodesService.length > 0) {
            for (index = 0; index < nodesService.length; index++) {
                var nodeClone = nodeOption.cloneNode(true);

                nodeClone.text = nodesService[index].text;
                nodeParent.appendChild(nodeClone);

            }
        }
        XDocument.View.EnableAutoUpdate();
        XDocument.View.ForceUpdate();

    } //insertChilds

     Does anyone have a tip?

    I think i don't understand something...

     I'm using InfoPath 2003 and jscript.

    Thank you

  • 02-19-2009 08:21 AM In reply to

    Re: Populating a combobox in a repeating table with different values for each row returned by a webservice

     OK, i finally found the solution, in the post :

    http://www.infopathdev.com/blogs/david/archive/2007/08/23/implementing-cascading-dropdowns-in-forms-server.aspx

     If you have a list in a repeating table that contains values coming from secondary data source, and different for each row, you have to create another list in main DOM (which will contain values). This second list must be at the same level than the first one (displaying values).

    In onAfterChange event, you have to copy nodes returned by second data source in the second list in main DOM (something like that)

     In onAfterChange :

    poNodeParent = eventObj.Parent.parentNode;
    psOptionNode = "my:child_revision_index_values"; //second list where values of secondary data source must be pasted

    //=======
    // FUNCTION: insertChilds
    // DESCRIPTION: Inserts service values as childs in the specified location
    //=======
    function insertChildsFromService(psService, poNodeParent, psOptionNode) {
        var index;

        // get results from service
        var theDataObject = XDocument.DataObjects.Item(psService);
        theDataObject.DOM.setProperty("SelectionNamespaces",
                                      'xmlns:dfs="http://schemas.microsoft.com/office/infopath/2003/dataFormSolution" ' +
                                      'xmlns:ns="..."');
        var nodesService = theDataObject.DOM.selectNodes("/dfs:myFields/dfs:dataFields/ns:getValuesResponse/ns:return");
        
        // copy option to insert and set selected value to "empty"
        var nodeOption = poNodeParent.selectSingleNode(psOptionNode);
        nodeOption.text = "";
        
        // remove all previous option
        if (poNodeParent.hasChildNodes()) {
            var bFirstDeleted = false;
            for (index = 0; index < poNodeParent.childNodes.length; index++) {
                if (poNodeParent.childNodes[index].nodeName == psOptionNode) {
                    if (bFirstDeleted) {
                        poNodeParent.removeChild(poNodeParent.childNodes[index]);
                    }
                    bFirstDeleted = true;
                }
            }
        }
        
        // insert options
        XDocument.View.DisableAutoUpdate();
        if (nodesService.length > 0) {
            for (index = 0; index < nodesService.length; index++) {
                if (nodesService[index].text != "") {
                    var nodeClone = nodeOption.cloneNode(true);
                    nodeClone.text = nodesService[index].text;
                    poNodeParent.insertBefore(nodeClone, nodeOption);
                }
            }
            poNodeParent.removeChild(nodeOption);
        }
        XDocument.View.EnableAutoUpdate();

    } //insertChildsFromService

Page 1 of 1 (2 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.