Skip to main content
I have a repeating section that contains a field which determines the decision of a line rule. How do I write the rule to make sure the line rule bases it's decision on the latest entry?
I am trying to create a solution to this problem using a Data Manipulation event in a new Activity that sets a flag. Then base the Line Rule on this flag. I believe this will work but am having some problems with the code. Could someone take a look at this and maybe identify what the issue is?

The error I am receiving is: XmlField my:Approval not found

the code:

Sub Main(ByVal K2 As ServerEventContext)

Dim SourceField As Object
Dim TargetField As Object
Dim i As Integer
Dim XmlNodeList As System.Xml.XmlNodeList

XmlNodeList = SourceCode.K2Utilities.XMLFieldMod.GetXMLNodeList(K2.ProcessInstance.XmlFields("my:Approval").Value,"/my:myFields/my:group1/my:TheApproval/")

For i=0 To (XmlNodeList.Count -1)

SourceField = XmlNodeList.Item(i).InnerXml

TargetField = SourceField


Next i

K2.ProcessInstance.DataFields("Approval").Value = TargetField

K2.Synchronous = True

End Sub


oops, syntax error



Sub Main(ByVal K2 As ServerEventContext)

Dim SourceField As Object
Dim TargetField As Object
Dim i As Integer
Dim XmlNodeList As System.Xml.XmlNodeList

XmlNodeList = SourceCode.K2Utilities.XMLFieldMod.GetXMLNodeList(K2.ProcessInstance.XmlFields("K2InfoPathSchema").Value,"my:myFields/my:group1/my:TheApproval/my:Approval")

Console.Write("Outside the for")

For i=0 To (XmlNodeList.Count -1)
Console.Write("inside the for")
SourceField = XmlNodeList.Item(i).InnerXml

TargetField = SourceField

Console.Write(TargetField & " " & i)

Next i

K2.ProcessInstance.DataFields("Approval").Value = TargetField

K2.Synchronous = True

End Sub


It worx 🙂
FWIW, the following XPath should return just the node you want without the need for a NodeList and loop:

my:myFields/my:group1/my:TheApproval/my:Approval[last()]
Thank you, I will try and test that when I refactor before sending to QA.

Reply