InfoPath Code - Loop through items in a secondary data source from a SharePoint List - Code-Tips.com - Web Development, Programming, SEO

Tuesday, September 22, 2009

InfoPath Code - Loop through items in a secondary data source from a SharePoint List

The article linked below demonstrates using JScript or VBScript, how to loop through items in a secondary data source until one is found which either contains a specific value, or has a specific value for a known attribute.

InfoPath - Update Repeating Elements in a Secondary Data Source


For example, when populating a CAML template with data from an InfoPath form so that it can be submitted to SharePoint, each field in the CAML template is a "field" element, which uses the value of the "name" attribute to determine which column/field in the SharePoint list to map to. The function (JScript or VBScript) in the linked article loops through each field element in the CAML XML data source until it finds the required field, by testing if the name attribute matches the name of the field/column to map data to. it then sets the value of the field element to the value of a field in the main data source of the InfoPath form.

Discussion relating to article include a solution to a scenario which required using the code provided in the article to loop through items in an InfoPath Form's secondary data source from a SharePoint list until the an item containing a specific value in the text column was found.

If found, the code was then re-used to populate the CAML template with data required to update the SharePoint list item. If the item was not found, a separate CAML template is populated with the data required to create a new SharePoint list item.

When the form is submitted, rules are configured with conditions to test if a new item is to be created in the SharePoint list, or updated if the item already exists. Two separate CAML templates are used here which required a separate data connection to submit the data to the SharePoint list using the Lists Web Service (updateListItem method) of the SharePoint site. Only one of the two submit data connections are executed to create or update a SharePoint list item as required.

See InfoPath Code - Loop Through Repeating Group in a Secondary Data Source for full details.


Related:
InfoPath - Update Existing SharePoint List Item Programmatically Using CAML
This article demonstrates how to set up data connections in an InfoPath form to Update an existing item in a SharePoint list using CAML and the Lists Web Service of the SharePoint Site.

InfoPath: Transfer Data Between 2 Forms
This article emplains how to transfer data from one InfoPath form to another, by loading the XML Document of the Second form and populating the required fields in the main data source of the form.  JScript is used to transfer the data.  Code examples are provided.

0 comments:

Post a Comment

Understood
This website is using cookies. More details