locked
Multiple-Selection List Box Control in InfoPath 2010 RRS feed

  • Question

  • I am learning InfoPath 2010, I made a blank InfoPath Design Form with one control - Multiple Selection List Box that contains a list of nine items.

    I made a simple web service that that has just this method which the InfoPath Design Form Submits to.

    [WebMethod]
    public string Test(string[] selectionresults)
    {
      if (null != selectionresults && selectionresults.Length > 0)
      {
        return string.Format("You have selected: {0} items.", selectionresults.Length);
      }

      return "No Items Selected";
    }

    Nothing fancy just to see if InfoPath submits what the user have selected to a web service always turns out an empty list being passed in.

    Is there something missing to send a complex list to a web service?  I have made both choices of submit to the webservice in InfoPath Wizard:

    Submit the following data for the selected parameter: * Field or Group: [/my:myFields/my:group1/my:field1]

    Include: [Text and child elements only  #] and [XML Subtree, including selected element  #].

    Every time I submit into the web service during debugging mode, the collectiion is empty.


    Thursday, May 26, 2011 8:23 PM

Answers

  • Never Mind, I just learned something major in InfoPath 2010.

    What a user needs to do is design a new InfoPath Form for SharePoint 2010.

    Add a new Manage Data Connection, connect to the web service method you want to send data to.

    In the Fields Properties box on is a drop down list usually defauted to "Main".  Select your new WCF Service Method and all the data fields are perfectly there.

    Drag the field into InfoPath Design Form, Preview it and Voila it all works.  Perfect No-Code Solution, this handled complex defined list and simple parameters magically.

    :)

     

    • Marked as answer by T2011 Friday, May 27, 2011 5:30 PM
    Friday, May 27, 2011 5:30 PM

All replies

  • Update *Did some more playing around with this*  I am not positive if this is the right answer for making this work yet but it is working rather is the best practice way - I do not know.

    I had to change the web method to this which introduce XMLDocument.

    [WebMethod]
    public void Test(XmlDocument selectionresults)
    {

      string val = string.empty;
      XmlNodeList elemList = selectionresults.GetElementsByTagName("my:field1");   
      for (int i = 0; i < elemList.Count; i++)   
      {        
         val = elemList[i].InnerText; 
      }
    }

    Then in the Web Service Data Connection Wizard on the Submit Parmeter Options section

    I had to set it to the "group" parameter which is /my:myFields/my:group1 and not /my:myFields/my:group1/my:field1.

    And set Include: to be XML Subtree, including selected element.

     

    Infopath View Form that obtained what the user selected and passed this information in an xml format to the webservice.

    From there, the developer would need to read the correct Element Tag.

    Question for Professional InfoPath Gurus: Is this the correct intended usage for Mutliple Selection List Box to pass selected object values to a web service as XML ?

    This complexes thing a little bit as I do not like hardcoding InfoPath groups and fields names in web services as if any updates to these tags names in InfoPath will force developer to update code for the web service.

    I am hoping there is something better than this that I am missing with my original question.

     

    Thursday, May 26, 2011 9:26 PM
  • This is the pre-2010 forum.  Are you for sure using 2010?

    This is definitely not beginner use of SharePoint to immediately create a custom web service for submitting values of a repeating field.  Do you not have SharePoint to use it with?  I can't help on evaluating the code, because I don't use any code when building InfoPath solutions, but I can help in other ways.  The key to the multi-select list box is that it is bound to a repeating text field, so keep that in mind when trying to deal with the XML.


    SharePoint Architect || Microsoft MVP || My Blog
    Planet Technologies || SharePoint Task Force
    Friday, May 27, 2011 2:01 AM
  • Sorry about the wrong forum type, I was on a Microsoft Infopath Forum and didnt realize I was creating this question in the wrong location.

     

    Okay, the reason I am testing these things out is because I am going to be making my first electronic InfoPath Form that will do the following:

    User goes to SharePoint to fill out a electronic form.  User will create a new item ( InfoPath Designed Form ), fills in the information and submits to SharePoint.

    This is all straight forward and simple, what I am trying to determine is we have existing wcf services and would like to send some of the information that is from the electronic form to the wcf service as this information collected is needed in several other advance applications the business uses.

    At first, I read Microsoft Documents on Infopath and found great information of sending InfoPath 2010 data fields to wcf service but the collection is what slowed me down.

    Maybe saving this to SharePoint List and a user can click on a ribbon button that calls a workflow that generates a task; the task being calling a wcf service that takes all the meta data fields and pass it to the wcf service method.  Now I have to see what SharePoint 2010 (possible using SharePoint Designer) have that can make this easier instead of InfoPath doing this. 

     

    Friday, May 27, 2011 4:34 PM
  • Never Mind, I just learned something major in InfoPath 2010.

    What a user needs to do is design a new InfoPath Form for SharePoint 2010.

    Add a new Manage Data Connection, connect to the web service method you want to send data to.

    In the Fields Properties box on is a drop down list usually defauted to "Main".  Select your new WCF Service Method and all the data fields are perfectly there.

    Drag the field into InfoPath Design Form, Preview it and Voila it all works.  Perfect No-Code Solution, this handled complex defined list and simple parameters magically.

    :)

     

    • Marked as answer by T2011 Friday, May 27, 2011 5:30 PM
    Friday, May 27, 2011 5:30 PM