Arasuser - Wednesday, October 21, 2009 2:11 AM:
Hi Everyone,
I want to assign the workflow to a particular identity through the method.
I need to take some information from the form and accordingly need to re-direct the workflow to a specific identity.
Can anyone give me some code example for this.
Thanks and Regards
Srii
tstickel - Thursday, October 22, 2009 3:38 PM:
In your question you state that you want to "take some information from the form". If the form you are refering to is the Form that is used to created a new item (e.g. the Part form, Document form, or some user defined form) and you already have associated a default workflow with the Itemtype then the code below can be used as an OnActivate method for the first Activity in the workflow. It assumes that the workflow has been defined with no assignments for any of the Activities, as this code will assign a particular Identity to each Activity and give that Identity a weight of 100.
'Called as an OnActivate method for the first activity in the workflow (after the Start)
Dim inn As Innovator = Me.newInnovator()
'Get the item that was responsible for intantiating this workflow
Dim controlledItem As Item = Me.newItem(Me.getAttribute("type"),"anGetControlledItem")
controlledItem.setID(Me.getID())
controlledItem = controlledItem.apply()
If controlledItem.getItemCount() <> 1 Then
Return inn.newError("Error retrieving the controlled item:" & controlledItem.getErrorDetail())
End If
'Get the program manager property from the item
Dim prodMgrID As String = controlledItem.getProperty("product_mgr")
'Get associated Workflow Process Activity to retrieve the parent Workflow Process ID
Dim wfProcAct As Item = inn.newItem("Workflow Process Activity","get")
wfProcAct.setProperty("related_id",Me.getID())
wfProcAct.setAttribute("select","source_id")
wfProcAct = wfProcAct.apply()
'Get all Workflow Process Activities for this parent Workflow Process
Dim wfProcActs As Item = inn.newItem("Workflow Process Activity","get")
wfProcActs.setProperty("source_id",wfProcAct.getProperty("source_id"))
wfProcActs.setAttribute("select","related_id")
wfProcActs = wfProcActs.apply()
'Loop through all Activities and add the product manager as activity assignee, with voting weigth of 100
'Ignore the Start and End Activities
Dim i As Integer = 0
For i = 0 To wfProcActs.getItemCount() - 1
Dim oneProcAct As Item = wfProcActs.getItemByIndex(i)
Dim wfAct As Item = inn.newItem("Activity","get")
wfAct.setAttribute("id",oneProcAct.getProperty("related_id"))
wfAct.setAttribute("select","id,name")
wfAct = wfAct.apply()
If (wfAct.getProperty("name") <> "Start" And wfAct.getProperty("name") <> "End") Then
Dim assignment As Item = Me.newItem("Activity Assignment","")
assignment.setAction("add")
assignment.setPropertyAttribute("locked_by_id","is_null","1")
assignment.setProperty("source_id",wfAct.getID())
assignment.setProperty("related_id",prodMgrID)
assignment.setProperty("voting_weight",100)
Dim res As Item = assignment.apply()
If res.isError() Then
Return inn.newError("Workflow Assignment: Error adding assignment: " & res.getErrorDetail())
End If
End If
Next
Arasuser - Monday, October 26, 2009 1:27 AM:
Hi Terry,
Thanks for the sample.
As you said I already have a form, which is linked to a workflow and in this workflow for some of the activities i already assigned people. Only for certain activities i need to choose a particular identity from the form. For example, the engineering manager will choose from item group which designer is going to do the design. So In that case i need to capture the designer choosen and redirect the workflow activity to that particular designer. How could i achieve this?
Regards
srii
tstickel - Monday, October 26, 2009 9:27 AM:
In the sample code, the following statement is used to determine which activities are to have their assignments modified:
If (wfAct.getProperty("name") <> "Start" And wfAct.getProperty("name") <> "End") Then
So in your case, if the only activity that you wanted to be redirected is "Design" then you would replace this with the statment:
If (wfAct.getProperty("name") = "Design") Then
The rest of the code should work without modification