Hello,
I have a requirement to check that the comments section of the workflow voting screen is filled in if following a certain path based on a certain person voting. There are multiple assignments for each activity
If I use the code on the event "On Vote" then I can check the path and identity, but comments are not shown (as they have not reached the server yet I assume?).
If I use the code on the event "On Close" then I can check path, identity and comments, but only if it is the last assignment of the activity.
Is anyone able to provide some guidance?
My code:
Dim MyInn As Innovator = Me.getInnovator()
Dim CtrlItem As Item = MyInn.newItem("Activity", "TRL_Get_Controlled_Item")
CtrlItem.setID(Me.getID())
CtrlItem = CtrlItem.apply()
Dim ActivityAsgn As Item = MyInn.newItem("Activity Assignment", "get")
ActivityAsgn .setAttribute("select", "")
ActivityAsgn .setProperty("source_id", Me.getID())
ActivityAsgn = ActivityAsgn .apply()
Dim CurrActAs As Item = Nothing
Dim wfcomments as string = ""
Dim q as string = ""
Dim pathtotake as string = ""
Dim userID As String = MyInn.getUserAliases()
For I As Integer = 0 To (ActivityAsgn .getItemCount() - 1)
CurrActAs = ActivityAsgn .getItemByIndex(I)
wfcomments = CurrActAs.getProperty("comments")
pathtotake = Me.getProperty("Path","")
q = ActivityAsgn .getItemByIndex(I).getRelatedItem().getProperty("id")
If q = userID Then
If pathtotake = "On Hold" Then
If wfcomments = "" Then
Return myInn.newError("Uh-Oh ID's dont match" + "<br/>" + q + "<br/>" + userID)
Return MyInn.newError("Comments are missing from your vote")
Else
Return MyInn.newError("wf comments " + wfcomments)
End If
Else
Return MyInn.newError("Not chosen an affected path")
End If
Else
Continue For
End If
Next I
Cheers mtk166, but this didn't appear to work. Got it working now though by setting as "On Close", and comparing the user identity of the active assignment with that of the logged in user and filtering by path. Had to also set an override path on the workflow though. Code below if anyone wants it. Works (for me) if there is multiple assignments, or just one, regardless if the assignment is a group identity or not.
Dim MyInn as Innovator = Me.getInnovator()
Dim CtrlItem As Item = MyInn.newItem("Activity", "TRL_Get_Controlled_Item")
CtrlItem.setID(Me.getID())
CtrlItem = CtrlItem.apply()
Dim ActivityAsgn As Item = MyInn.newItem("Activity Assignment", "get")
ActivityAsgn .setAttribute("select", "")
ActivityAsgn .setProperty("source_id", Me.getID())
ActivityAsgn = ActivityAsgn .apply()
Dim CurrActAs As Item = Nothing
Dim wfcomments as string = ""
Dim q as string = ""
Dim userID As String = MyInn.getUserAliases()
For I As Integer = 0 To (ActivityAsgn .getItemCount() - 1)
CurrActAs = ActivityAsgn .getItemByIndex(I)
wfcomments = CurrActAs.getProperty("comments")
q = ActivityAsgn .getItemByIndex(I).getRelatedItem().getProperty("id")
Dim myItemCM As Item = Me.newItem("Identity", "get")
myItemCM.setAttribute("select", "id")
myItemCM.setID(q)
Dim relationshipCM As Item = Me.newItem("Member", "get")
relationshipCM.setAttribute("select", "related_id")
Dim relatedItemCM As Item = Me.newItem("Identity", "get")
relatedItemCM.setAttribute("select", "id, keyed_name")
relationshipCM.setRelatedItem(relatedItemCM)
myItemCM.addRelationship(relationshipCM)
Dim resultsCM As Item = myItemCM.apply()
' Test for an error.
If resultsCM.isError() Then
Return MyInn.newError("Error: " + resultsCM.getErrorDetail())
End If
' Get a handle to the Member Items.
Dim memberItemsCM As Item = resultsCM.getRelationships("Member")
Dim countCM As Integer = memberItemsCM.getItemCount()
Dim iCM As Integer
Dim CMID_List As String = ""
' Iterate over the Member Items
For iCM = 0 To countCM - 1
' Get a handle to the relationship Item by index.
Dim memberItemCM As Item = memberItemsCM.getItemByIndex(iCM)
Dim IdentityID_method1CM As String = memberItemCM.getRelatedItem().getID()
CMID_List = CMID_List + "<br>" + IdentityID_method1CM
Next
Dim pathtotake as string = CurrActAs.getProperty("path")
If pathtotake = "Approve" Then Return Me
If CMID_List = "" Then ' not a group identity
If q = userID Then
If wfcomments = "" Then
Return MyInn.newError("Please fill in the comments section as to why you are voting to " + pathtotake)
Else
'Return MyInn.newError("wf comments: " + wfcomments)
Exit For
End If
Else
Continue For
End If
ElseIf CMID_List.Contains(userID)
If wfcomments = "" Then
Return MyInn.newError("Please fill in the comments section as to why you are voting to " + pathtotake)
Else
'Return MyInn.newError("wf comments: " + wfcomments)
Exit For
End If
End If
Next I
Return Me
Cheers mtk166, but this didn't appear to work. Got it working now though by setting as "On Close", and comparing the user identity of the active assignment with that of the logged in user and filtering by path. Had to also set an override path on the workflow though. Code below if anyone wants it. Works (for me) if there is multiple assignments, or just one, regardless if the assignment is a group identity or not.
Dim MyInn as Innovator = Me.getInnovator()
Dim CtrlItem As Item = MyInn.newItem("Activity", "TRL_Get_Controlled_Item")
CtrlItem.setID(Me.getID())
CtrlItem = CtrlItem.apply()
Dim ActivityAsgn As Item = MyInn.newItem("Activity Assignment", "get")
ActivityAsgn .setAttribute("select", "")
ActivityAsgn .setProperty("source_id", Me.getID())
ActivityAsgn = ActivityAsgn .apply()
Dim CurrActAs As Item = Nothing
Dim wfcomments as string = ""
Dim q as string = ""
Dim userID As String = MyInn.getUserAliases()
For I As Integer = 0 To (ActivityAsgn .getItemCount() - 1)
CurrActAs = ActivityAsgn .getItemByIndex(I)
wfcomments = CurrActAs.getProperty("comments")
q = ActivityAsgn .getItemByIndex(I).getRelatedItem().getProperty("id")
Dim myItemCM As Item = Me.newItem("Identity", "get")
myItemCM.setAttribute("select", "id")
myItemCM.setID(q)
Dim relationshipCM As Item = Me.newItem("Member", "get")
relationshipCM.setAttribute("select", "related_id")
Dim relatedItemCM As Item = Me.newItem("Identity", "get")
relatedItemCM.setAttribute("select", "id, keyed_name")
relationshipCM.setRelatedItem(relatedItemCM)
myItemCM.addRelationship(relationshipCM)
Dim resultsCM As Item = myItemCM.apply()
' Test for an error.
If resultsCM.isError() Then
Return MyInn.newError("Error: " + resultsCM.getErrorDetail())
End If
' Get a handle to the Member Items.
Dim memberItemsCM As Item = resultsCM.getRelationships("Member")
Dim countCM As Integer = memberItemsCM.getItemCount()
Dim iCM As Integer
Dim CMID_List As String = ""
' Iterate over the Member Items
For iCM = 0 To countCM - 1
' Get a handle to the relationship Item by index.
Dim memberItemCM As Item = memberItemsCM.getItemByIndex(iCM)
Dim IdentityID_method1CM As String = memberItemCM.getRelatedItem().getID()
CMID_List = CMID_List + "<br>" + IdentityID_method1CM
Next
Dim pathtotake as string = CurrActAs.getProperty("path")
If pathtotake = "Approve" Then Return Me
If CMID_List = "" Then ' not a group identity
If q = userID Then
If wfcomments = "" Then
Return MyInn.newError("Please fill in the comments section as to why you are voting to " + pathtotake)
Else
'Return MyInn.newError("wf comments: " + wfcomments)
Exit For
End If
Else
Continue For
End If
ElseIf CMID_List.Contains(userID)
If wfcomments = "" Then
Return MyInn.newError("Please fill in the comments section as to why you are voting to " + pathtotake)
Else
'Return MyInn.newError("wf comments: " + wfcomments)
Exit For
End If
End If
Next I
Return Me