[SharePoint workflow infopath] submit a form in the infopath form and start the Workflow

Source: Internet
Author: User

The powerful support for workflows in Moss allows us to do a lot of applications.

For example, we can use the form library as an approval form and then add a process to the form library.

We may want users to fill in the form with information they need when starting the workflow, such as setting the approver.

Our form will be like the following, including the content to be approved, and other workflow settings such as set approver.

We also hope that when you click "save", you can submit a form and start the workflow according to the approver set by the user.

(

The default mode of moss is to start a workflow on another page after the form is submitted, which requires two steps. This is a poor user experience.

The best health check is "one step in place". You only need to submit and start the job on one interface.

)

 

Therefore, we need to do some work on the "save" button in the infopath form services form to meet this requirement.

My ideas are as follows:

Use vsta to add the "save" button in the form template of the form libraryCodeTo submit the form and start the workflow.

1) when designing a form template, set a dataconnection for the infopath form)

The submitted connection includes the URL of the submitted document library and the default naming rules for file names. This commit connection is required for submitting a form and starting a workflow.

 

2) Add code to the "save" button of the infopath form (The following code is used as an example:):

 
Xpathnavigator field2 =This. Maindatasource. createnavigator (). selectsinglenode ("/My: myfields/My: field2", Namespacemanager); // get the object for submitting the connection. filesubmitconnection corresponds to the connection class filesubmitconnection osssubmit = (filesubmitconnection) submitted to the SharePoint document library)This. Dataconnections ["Osssubmit"]; // We can use a project in the form as the file name when submitting the form, or use other naming rules, or you can specifyStringTempfilename = field2.value +"_"+ Datetime. Now. tostring (). Replace (":","_"); // Set the file name of the submitted form. osssubmit. filename. setstringvalue (tempfilename +". Xml");
 
// Execute and submit osssubmit. Execute ();
// At this step, the form has been submitted to the document library, and then start the form workflowTry{// According to the folderurl attribute of the submitted connection, you can obtain the website set spsite mysite = of the document library.NewSpsite (osssubmit. folderurl );
 
// Based on the form name and folderurl, you can spell out the complete URL of the submitted form.StringFileurl = osssubmit. folderurl +"/"+ Tempfilename +". Xml";If(Osssubmit. folderurl. endswith ("/") {Fileurl = osssubmit. folderurl + tempfilename +". Xml";}// Using folderurl, you can obtain the splist object splist mylist = mysite. rootweb. getlist (osssubmit. folderurl) corresponding to the document library using the spweb. getlist method );
 
// You can obtain the splistitem object splistitem mylistitem = mysite. rootweb. getlistitem (fileurl) corresponding to the complete URL of the previously uploaded form );
// Obtain a workflow associated with spworkflowassociation mywfass = mylist. workflowassociations. getassociationbyname ("Review", System. Globalization. cultureinfo. currentculture );
 
// Eventdata is the parameter required when the workflow is started, such as the approver. Replace the corresponding information in eventdata with the startup parameter set in the form.

/* The associated information defines the workflow startup parameters in the following XML format. All we need to do is to replace the corresponding field values in the form with the corresponding content in the XML, marked in red

<My: myfields XML: lang = \ "ZH-CN \" xmlns: xsi = \ "http://www.w3.org/2001/xmlschema-instance\" xmlns: My = \ "external" xmlns: XD = \ "external">

<My: Instructions> review it! </My: Instructions>

<My: assignees> litwareinc \ Administrator; litwareinc \ demouser2 </My: assignees>

</My: myfields>

*/
StringEventdata = mywfass. associationdata;
Mysite. allowunsafeupdates =True;
Mysite. rootweb. allowunsafeupdates =True;

// Start the Workflow Based on the Set Information
Mysite. workflowmanager. startworkflow (mylistitem, mywfass, eventdata );
}
Catch{}

Update: Download example here

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.