Thursday, February 11, 2016

How to set InfoPath field value on dropdown change event in SharePoint 2010 and 2013

Problem

We have a Dropdown in InfoPath which is populated from external data source (SharePoint List. e.g. TimeSheet List having fields ProjectName, %Complete and Type. Dropdown is showing Project Names). We want to populate infopath field (Type) from SharePoint based on selected Project in dropdown.

Solution

I suppose you have already Filled Dropdown from Timesheet List and or applied filtering if required, If not, you can follow my post How to Filter Infopath Dropdown.

Select the Project dropdown that we created in previous article and from the "Home" ribbon, select Add Rule->This Field Changes -> Set a Field's Value option as shown in the below image.


This will open up Rules detail dialog. you can click on the button next to "Fields" and select "Type" on the "Select a Field or Group" dialog.


Now we will set the Value textbox. Click on the button next to "Value" button and following is the series of steps you will follow,

  1. Click on the function button next to value on Rule Detail dialog.
  2. Click on the "Insert Field or Group" button on the "Insert Formula" dialog.
  3. Select the Field "Project Type" and click on the "Filter Data.." button. We need to continue to the step 4 because we want to get the same project type as selected as Project in the project dropdown.
  4. On the "Filter Data" screen, click on "Add/Modify" button.
  5. On the "Specify Filter Conditions" dialog, click on the first dropdown and select last option of "Select a Field or Group" option. in the newly opened dialog of "Select a Field or Group" dialog, select ID column of list connection because we selected "ID" as value field of Project dropdown in previous article.
    1. Select "Is equal to" in second dropdown
    2. enter anything in the last dropdown. (e.g. enter 1 in this dropdown. we will change it anyway through step 6 below).
  6. Now every thing is set and click "OK" button on all the dialogs until "Insert Formula"  dialogbox. on this dialog box, enable "Edit XPath (Advanced)" checkbox and replace 1 with current() function. See image below.

The generated XPath will look like following,

xdXDocument:GetDOM("TimeSheet Projects")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Project_x0020_Type[../d:ID = 1]

After changing 1, it will look like this,

xdXDocument:GetDOM("TimeSheet Projects")/dfs:myFields/dfs:dataFields/d:SharePointListItem_RW/d:Project_x0020_Type[../d:ID = current()]

Click OK and you are good to go.

No comments:

Post a Comment