|
Users can either leverage the existing event handlers for process initiation or call the API explicitly to initiate the processes for SPS Integration. We do recommend to leverage the existing event handler for the process initiation because our AgilePoint SPS event handlers perform extra operations besides the process initiation. These extra operations are required as part of the SPS Integration.
One example is to initiate an InfoPath based process from an external application. Rather than having a user to log into SharePoint and fill out a form, you can create an external module to upload a plain InfoPath form (using pre-defined template and UploadInfoPathForm Web service) into the form library which triggers the event handler to initiate a new process instance. You can include a step in the process to fill out data into the form by using the UpdateInfoPathForm AgilePart.
Attached is a sample project which has a C# console program to access the APWS\AgileParts.asmx Web service to call UploadInfoPathForm to upload a plain form (template.xml) to the SharePoint Form library. If the form library is associated with a process template, a process instance will be initiated. In the sample code, an UpdateInfoPathForm call is made to update the InfoPath Form with data from a sample file (UpdateForm.xml).
IMPORTANT NOTE: URLs are case sensitive. When referring to URLs in your code, ensure you are using the exact case. If the correct case is not used, processes may not be initiated.
The following is the code snippet:
private void button1_Click(object sender, System.EventArgs e)
{
//Plain InfoPath Form to upload
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("c:\\template.xml");
//Access the AgilePart web service
APWS.AgileParts apws = GetAPWS( "http://virtual:8080" );
//Upload the plain InfoPath to a specific Form Library
string s = apws.UploadInfoPathForm("http://virtual:8080/sites/AscentnFinancialSite/TestUpload", "TestUpload", "yyMMdd", "0000", xmlDoc.OuterXml);
textBox1.Text = s;
string s2 = apws.GetProcessInitialAttributes(s);
textBox2.Text = s2;
//Update the InfoPath Form with the latest data
xmlDoc.Load("c:\\UpdateForm.xml");
apws.UpdateInfoPathForm(s, xmlDoc.OuterXml);
}
The above sample is built under the Virtual PC environment with SharePoint installed at http://virtual:8080. The SharePoint Form Library for this sample is: http://virtual:8080/sites/AscentnFinancialSite/TestUpload and the InfoPath Form associated with the library is template.xsn as attached in the zip file.
To test the sample:
-
Make the appropriate changes to the SharePoint URL, Form Library and test login credential.
-
Open and rebuild the solution, make sure no error is occurred.
-
Copy the template.xml and UpdateForm.xml to c:\ folder.
-
Run the Upload.exe under the bin\Debug folder to simulate the test.
Similarly, you can also implement your own AgilePart that leverages UploadInfoPathForm in the existing AgilePart Web service, the following is code snippet:
#region AgilePart : UploadInfoPathForm
[
Description("UploadInfoPathForm"),
AgilePartDescriptor( typeof(UpdateInfoPathFileDescriptor) )
]
public void UploadInfoPathForm(
WFProcessInstance pi,
WFAutomaticWorkItem w,
IWFAPI api,
NameValue[] parameters)
{
WriteToLog("Start update");
try
{
Hashtable h = Convert2Hasttable( parameters );
string fileUrl = (string)h["InfoPathFileURL"];
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("c:\\template.xml");
WriteToLog(xmlDoc.OuterXml);
WriteToLog(fileUrl);
APWS.AgileParts apws = GetAPWS( fileUrl );
apws.UploadInfoPathForm(fileUrl, "TestUpload", "yyMMdd", "0000", xmlDoc.OuterXml);
if( w.Synchronous ) MarkSuccess(api, pi, w, parameters);
WriteToLog("succes");
}
catch ( Exception ex )
{
HandleException(api, pi, w, parameters, ex );
WriteToLog(" Exception = " + ex.ToString());
}
WriteToLog("");
}
#endregion
|