How to synchronize automatically InfoPath field with form librairy column without coding
When developing forms with InfoPath 2007 that will be published in SharePoint Form Server, you often need to synchronize your form field with SharePoint library column in order to switch form view depending on that field.
InfoPath 2007 and SharePoint 2007 provide standard functionalities to achieve it without any code.
Sample scenario:
Let’s say you have two views in your form (ViewUSR and ViewUSR_RO) and depending on the “CDPSStatus” field value in the main data source, the form will change the view displayed to the user when he opens the form. The “Status” field can be modified externally by the user on the published form library column or within a workflow.
Here are steps to do it:
· Create a field "CDPSState" in the InfoPath form Main Data source
· On the form option, add rules, add condition and action that will switch to the required view.
· Publish the form and add "CDPSState" field to be available in MOSS. (This action is called promoting the field and it will be synchronized automatically with the value of the library column)
· Modify this field by editing the field to "Completed" and your form should be synchronized and display the correct view (depending on your rule condition).
Working with Workflow: You can use this approach to display different views of your form depending on your workflow step. Just modify the promoted field within your workflow code.
Sample code to modify the promoted field by code (just as a SPListItem column)
using (SPSite site = new SPSite("https://Site"))
{
using (SPWeb web = site.OpenWeb("/"))
{
SPList list = web.Lists["ListName"];
SPListItem item = list.Items[0];
item.Properties["CDPSState"] = "Completed";
item.Update();
}
}
Without your workflow, you will use "workflowProperties.Item" to get the SPListItem.
*Philippe*