Skip to main content
I have an InfoPath process. As expected I can access the InfoPath form Xml as: K2.ProcessInstance.XmlFields["K2InfoPathSchema"] within the InfoPath activity/event, and the next activity which is a default server event [Determine Next Approver].

When the line rules execute from the [Determine Next Approver] event the results of K2.ProcessInstance.XmlFields["K2InfoPathSchema"] = "". I have verified that it is empty. Also, if I work around the empty xml in the line rule so that [Forward To Next Approver] is true then the destination rule in [Notify Next Approver] also says that the InfoPath xml is "".

Does anyone have any idea what is going on here?
I was able to work around this by expictly storing the K2InfoPathSchema xml in my one ProcessInstance.DataField, but the xml gets to be ~10MB in size. I really don't want to be storing multiple copies of this string when it really should be accessible already.

Thanks in advance.
What process fields are you setting in the server event?

Is there any chance that you may be clearing the xml field in that server event?
I when through the server event, just to be sure. I am setting my own ProcessInstance data field "FormXml" to the value of K2InfoPathSchema XmlField because the data keeps disappearing. There is no place in the server event that I would set the value of K2InfoPathSchema = "".
Hi,

The following should explain why this happens.

http://forum.k2workflow.com/files/ipact_555.jpg

Process XML field refers to ProcessInstance.XMLField( K2InfoPathSchema )
Activity XML field refers to ActivityDestinationInstance.XMLField( K2InfoPathSchema )


When updating field values in XML data fields, the placement of the server event that performs the update will determine whether to use ProcessInstance or ActivityDestinationInstance XML fields for the update.

For server events placed before an InfoPath Client Event (Set Authorisation Level in Figure 1), any XML field value updates should be performed on the Process XML field and not the Activity XML field. The Activity XML field cannot be used here because it is empty prior to the execution of the InfoPath Client Event. If you do, you are most likely to hit an error of the following nature: The root element is missing.

For server events after the InfoPath Client Event (Timestamp Approval), the Activity XML field should be used for updating XML field values. Upon completing the final server event, the implicit Succeeding Rule within the InfoPath Activity will be executed, and it copies values from Activity XML fields to Process XML fields. Consequently, any updates made to Process XML field after the InfoPath Client Event will be overwritten by Activity XML field.
The InfoPath Activity s Succeeding Rule is embedded in the code window and does not register on the GUI view of the rule. Thus, it is not immediately apparent to most K2.net developers that XML field value updates are to be made to Activity XML fields.

Example code in Set Authorisation Level Server Event
The following code will set the value of ManagerDisplayNextAuthSelection based on the value of PurchaseTotal.

Sub Main(ByVal K2 As ServerEventContext)
K2.Synchronous = True

Dim PurchaseTotal As double= CDbl(SourceCode.K2Utilities.XMLFieldMod.GetXMLValue(K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value,"my:PurchaseOrder/my:Order/my:OrderPriceTotal"))

If PurchaseTotal > CDbl(K2.StringTable("Level2ApprovalLimit")) Then
K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value = SourceCode.K2Utilities.XMLFieldMod.SetXMLValue(K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value,"my:PurchaseOrder/my:Manager/my:ManagerDisplayNextAuthSelection","True")
Else
K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value = SourceCode.K2Utilities.XMLFieldMod.SetXMLValue(K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value,"my:PurchaseOrder/my:Manager/my:ManagerDisplayNextAuthSelection","False")
End If

End Sub


Example code in Timestamp Approval Server Event
The following code will set a timestamp into ManagerApprovalDateTime.

Sub Main(ByVal K2 As ServerEventContext)
K2.Synchronous = True

Dim sTimeStamp As String = Now.ToString("MM/dd/yyyy HH:mm:ss tt")
K2.ActivityInstanceDestination.XmlFields("K2InfoPathSchema").Value = SourceCode.K2Utilities.XMLFieldMod.SetXMLValue(K2.ActivityInstanceDestination.XmlFields("K2InfoPathSchema").Value,"my:PurchaseOrder/my:Manager/my:ManagerApprovalDateTime",sTimeStamp)

End Sub


Hope this helps

Reply