Skip to main content
I am at a complete loss. I have a Default Server event where I am trying to add some new XML nodes to a schema that was pulled into K2 from an InfoPath form.

Here is the code:

Dim strK2InfoPathSchema As String = K2.ProcessInstance.XmlFields(PRGlobalConstants.SCHEMA_INFOPATH).Value.ToString()
Dim objIPDoc As New System.Xml.XmlDocument
objIPDoc.LoadXml(strK2InfoPathSchema)

'' Add namespace
Dim objNSMgr As New XmlNamespaceManager(objIPDoc.NameTable)
Dim objITT As XmlElement
objITT = objIPDoc.DocumentElement
Dim objNS As String = objITT.GetNamespaceOfPrefix(PRGlobalConstants.SCHEMA_INFOPATH_NS_PREFIX)
objNSMgr.AddNamespace(PRGlobalConstants.SCHEMA_INFOPATH_NS_PREFIX, objNS)

Dim objNewDoc As New XmlDocument
objNewDoc.LoadXml("<my:AdditionalManager xmlns:my=""http://schemas.microsoft.com/office/infopath/2003/myXSD/2005-07-21T20:40:37""><my:AdditionalManagerFirstName>PR</my:AdditionalManagerFirstName><my:AdditionalManagerLastName>QA1</my:AdditionalManagerLastName><my:AdditionalManagerEmail>prqa1@blah.com</my:AdditionalManagerEmail><my:AdditionalManagerDecisionDate /><my:AdditionalManagerApproved>1</my:AdditionalManagerApproved><my:AdditionalManagerComments /><my:AdditionalManagerActiveDirectoryID>blahprqa1</my:AdditionalManagerActiveDirectoryID><my:AdditionalManagerType>QA Manager</my:AdditionalManagerType></my:AdditionalManager>")

'' Select the ad hoc users group node
Dim objAdHocManagersNode As XmlNode = objIPDoc.SelectSingleNode(PRGlobalConstants.XPATH_IP_FULL_AD_HOC_MGRS, objNSMgr)
objAdHocManagersNode.AppendChild(objIPDoc.ImportNode(objNewDoc.DocumentElement, True))


LogUtility.LogEvent("PR_DEBUG", "before new " & strK2InfoPathSchema , System.Diagnostics.EventLogEntryType.Information)

'' update form content
strK2InfoPathSchema = SourceCode.K2Utilities.XMLFieldMod.SetXMLValue(strK2InfoPathSchema, PRGlobalConstants.XPATH_ITT, objIPDoc.InnerXml)

'' save back
K2.ProcessInstance.XmlFields(PRGlobalConstants.SCHEMA_INFOPATH).Value = strK2InfoPathSchema

LogUtility.LogEvent("PR_DEBUG", "after new " & K2.ProcessInstance.XmlFields(PRGlobalConstants.SCHEMA_INFOPATH).Value, System.Diagnostics.EventLogEntryType.Information)


I am throwing some stuff out the event viewer here to help me debug.

This is the before log from the code above:
<my:AdditionalManagers><my:ManagerGroupApproved>false</my:ManagerGroupApproved><my:AdditionalManager><my:AdditionalManagerFirstName></my:AdditionalManagerFirstName><my:AdditionalManagerLastName></my:AdditionalManagerLastName><my:AdditionalManagerEmail></my:AdditionalManagerEmail><my:AdditionalManagerDecisionDate></my:AdditionalManagerDecisionDate><my:AdditionalManagerApproved>1</my:AdditionalManagerApproved><my:AdditionalManagerComments></my:AdditionalManagerComments><my:AdditionalManagerActiveDirectoryID></my:AdditionalManagerActiveDirectoryID><my:AdditionalManagerType>Approver</my:AdditionalManagerType></my:AdditionalManager></my:AdditionalManagers>

Here is the after:

<my:AdditionalManagers><my:ManagerGroupApproved>false</my:ManagerGroupApproved><my:AdditionalManager><my:AdditionalManagerFirstName></my:AdditionalManagerFirstName><my:AdditionalManagerLastName></my:AdditionalManagerLastName><my:AdditionalManagerEmail></my:AdditionalManagerEmail><my:AdditionalManagerDecisionDate></my:AdditionalManagerDecisionDate><my:AdditionalManagerApproved>1</my:AdditionalManagerApproved><my:AdditionalManagerComments></my:AdditionalManagerComments><my:AdditionalManagerActiveDirectoryID></my:AdditionalManagerActiveDirectoryID><my:AdditionalManagerType>Approver</my:AdditionalManagerType></my:AdditionalManager><my:AdditionalManager><my:AdditionalManagerFirstName>PR</my:AdditionalManagerFirstName><my:AdditionalManagerLastName>QA1</my:AdditionalManagerLastName><my:AdditionalManagerEmail>prqa1@blah.com</my:AdditionalManagerEmail><my:AdditionalManagerDecisionDate /><my:AdditionalManagerApproved>1</my:AdditionalManagerApproved><my:AdditionalManagerComments /><my:AdditionalManagerActiveDirectoryID>blahprqa1</my:AdditionalManagerActiveDirectoryID><my:AdditionalManagerType>QA Manager</my:AdditionalManagerType></my:AdditionalManager></my:AdditionalManagers>

As we can see, the new XML gets into the out put. Here is the problem, when process continues to the next continues to the next activity, the after xml is LOST and I only have te before XML. Is there a reason why this is being lost.
In what type of activity template is the server event located - is it a default activity or an infopath activity?
It is a default server event. So, in this instance I have an InfoPath activity. I then have two events on that activity. The first is the IP client event. The second is a default server event which does the code above.
I assume that this is an InfoPath ACTIVITY, since you mentioned that you have an InfoPath client event in the same activity.

Have a look at the succeeding rule for the activity (it may appear to be blank, but switch to 'use code' and then 'edit code') - you will see that an Infopath activity copies an Activity XML datafield (by default called K2InfoPathSchema) to a process datafield (b y default called K2InfoPathSchema), which is why the changes you are trying to apply in your server event are being lost. (In your case, it looks like your XML field is called PRGlobalConstants.SCHEMA_INFOPATH)

You have 2 choices - you can use your current method but instead of updating the PROCESS XML datafield, update the ACTIVITY XML datafield. Alternatively, add a default activity after this InfoPath activity and move the server event into this activity. That should do it.

look at this thread for some info on how the InfoPath activity works:
http://forum.k2workflow.com/viewtopic.php?t=997

Hope this helps - please let me know if this solves your problem.
Thanks for the speedy response. You are correct. I also found this too http://forum.k2workflow.com/viewtopic.php?t=851

Reply