Skip to main content
Hi All,

I have been working with custom events for some time now but have failed to get to grips with generation of rules. I have a standard process which I generate using a custom Process Event. The process data variables are generated along with the Activities, Events and Lines. This all works great (apart from my current woe and the inability to control line placement).

However, in two places I wish to control the spliting of the process based on a boolean instance variable; right branch when true, left when false.

Everything looks simple when generating the line rules within the event properties wizard, however there is no way to do the same thing using K2.Studio automation that I see.

Has anyone managed this automated generation or is it a black art known only to the labs in South Africa? Any feedback would be much appreciated.

Regards
Graham
Hi Graham,

I am not sure I follow...

What do you mean by -
"I have a standard process which I generate using a custom Process Event"

Is the problem with generation of LineRules i.e. you do not know which methods and properties to call? OR
Is the problem that you define the LineRule but it is not persisted? OR
Is the problem that the dynamically created datafields can not be used in the linerules?

Have you had a look at the Help file and specifically at the 'AddLines' and 'AddLineRule' procedures defined in the sample code?
    Public Sub AddLines(ByVal K2 As K2Studio.Process)
Dim oStartLine As K2Studio.Line
Dim oSourceActivity As K2Studio.Activity
Dim oDestActivity As K2Studio.Activity

oSourceActivity = K2.Activities.Item("Start")
oDestActivity = K2.Activities.Item("HR Approval")
oStartLine = K2.Lines.Add("Start Line", oSourceActivity.Name, oDestActivity.Name, 1, "", oSourceActivity.Top, oSourceActivity.Top, oDestActivity.Top, oDestActivity.Top)
oStartLine.Description = "Line connecting " & oSourceActivity.Name & " and " & oDestActivity.Name

oSourceActivity = K2.Activities.Item("HR Approval")
oDestActivity = K2.Activities.Item("Manager Approval")
oStartLine = K2.Lines.Add("HR to Manager", oSourceActivity.Name, oDestActivity.Name, 1, "", oSourceActivity.Top, oSourceActivity.Top, oDestActivity.Top, oDestActivity.Top)
oStartLine.Description = "Line connecting " & oSourceActivity.Name & " and " & oDestActivity.Name
AddLineRule(oStartLine, "Approved")

oSourceActivity = K2.Activities.Item("HR Approval")
oDestActivity = K2.Activities.Item("Declined")
oStartLine = K2.Lines.Add("HR to Declined", oSourceActivity.Name, oDestActivity.Name, 5, "", oSourceActivity.Top, oSourceActivity.Top, oDestActivity.Top, oDestActivity.Top)
oStartLine.Description = "Line connecting " & oSourceActivity.Name & " and " & oDestActivity.Name
AddLineRule(oStartLine, "Declined")

oSourceActivity = K2.Activities.Item("Manager Approval")
oDestActivity = K2.Activities.Item("Approved")
oStartLine = K2.Lines.Add("Approved", oSourceActivity.Name, oDestActivity.Name, 1, "", oSourceActivity.Top - 5, oSourceActivity.Top, oDestActivity.Top, oDestActivity.Top)
oStartLine.Description = "Line connecting " & oSourceActivity.Name & " and " & oDestActivity.Name
AddLineRule(oStartLine, "Approved")

oSourceActivity = K2.Activities.Item("Manager Approval")
oDestActivity = K2.Activities.Item("Declined")
oStartLine = K2.Lines.Add("Declined", oSourceActivity.Name, oDestActivity.Name, 1, "", oSourceActivity.Top + 5, oSourceActivity.Top, oDestActivity.Top, oDestActivity.Top)
oStartLine.Description = "Line connecting " & oSourceActivity.Name & " and " & oDestActivity.Name
AddLineRule(oStartLine, "Declined")

End Sub

Public Sub AddLineRule(ByVal K2 As K2Studio.Line, ByVal type As String)
K2.LineRule.Code = "Public Sub Main(ByRef K2 As LineRuleContext)" & vbNewLine & _
" K2.LineRule = False" & vbNewLine & _
" If (Func1(K2) = True) Then" & vbNewLine & _
" K2.LineRule = True" & vbNewLine & _
" Else" & vbNewLine & _
" K2.LineRule = False" & vbNewLine & _
" End If" & vbNewLine & _
"End Sub" & vbNewLine & _
"Private Function Func1(ByRef K2 As LineRuleContext) as Boolean" & vbNewLine & _
" Func1 = False" & vbNewLine & _
" Dim strTemp1 as String" & vbNewLine & _
" Dim strTemp2 as String" & vbNewLine & _
" Dim strTempLD As String" & vbNewLine & _
" Dim firstVariable as Object" & vbNewLine & _
" Dim secondVariable as Object" & vbNewLine & _
" Dim LogicalData As Object" & vbNewLine & _
" Dim Counter As Integer = 0" & vbNewLine & _
" Dim ActInstDest As Object" & vbNewLine & _
" secondVariable = """ & type & """" & vbNewLine & _
" For Each ActInstDest In K2.LineInstance.StartActivityInstance.Destinations" & vbNewLine & _
" firstVariable = ActInstDest.DataFields(""ApprovalStatus"").Value" & vbNewLine & _
" If firstVariable.ToString.ToUpper = secondVariable.ToString.ToUpper Then" & vbNewLine & _
" Counter += 1" & vbNewLine & _
" End If" & vbNewLine & _
" Next" & vbNewLine & _
" If Counter = K2.LineInstance.StartActivityInstance.Slots Then" & vbNewLine & _
" Return True" & vbNewLine & _
" Else" & vbNewLine & _
" Return False" & vbNewLine & _
" End If" & vbNewLine & _
"End Function"
K2.LineRule.SaveCodeWindow()
End Sub


Regards,
Ockert
Hi Ockert,

I mean my process is standard in the way that the vast majority of the activities are the same and known in advance. Therefore I have designed a custom process event that builds the basic workflow. This works well but I now want to add rule code but not have to worry about the lower level source code as you have shown in your example.

The rule GUI provides the abilty to define rules in an abstract form indepedant of VB or C# - this is the format that I wish to understand and use. However, I can live with the hardcoding but an user must first delete before enhancing and standard line rule conditiond supplied by my custom process event.

Hope this makes my first post a little clearer.

Regards
Graham
Hi Graham,

Yes, thank you - it is a lot clearer to me now.

Unfortunately, No, there's no method or property that will take this 'abstract' format and convert that to VB or C# code. In essence this is exactly what the Rule GUI and wizard does.

Since this LineRule template is not directly part of the K2Studio object model but rather an add-in, its methods are not exposed.

Regards,
Ockert
Hi Ockert,

That is unfortunate - I thought I could do some smart stuff in this case. Never mind; hardcoding here I come 😎. Thanks anyway.

Regards,
Graham

Reply