Scenario:There is a configuration list to configure the approver for each step. The configuration list fields are as follows:
Title:Workflow name
Level1approver: Step 1 approver
Level2approver: Step 2 approver
Procedure:
Please first understand the executecode activity:Http://www.cnblogs.com/jianyi0115/archive/2011/04/17/2018872.html
Create a workflow, add two string type workflow variables: level1approver , level2approver
Drag oneExecutecodeActivity, drag twoTaskActivity,TaskActiveUserBind propertiesLevel1approver,Level2approver.
Draw line connectionStart-> ExecuteCode-Task1-> task2.
Double-clickExecutecode, Write the script as follows:
Queryfield titlefield = new queryfield ("title ");
Splist cfglist = This. Web. Lists ["Approver Configuration"]; //Retrieve list
VaR cfgitem = listquery. From (cfglist). Where (titlefield ="Business card application"). Getitems () [0]; //Configuration item retrieved
//Get Field Value
Spfielduservalue user1value = cfgitem. Fields. getfield ("level1approver"). getfieldvalue (cfgitem ["level1approver"]. tostring () as spfielduservalue;
VaR level1user = user1value. User. loginname;
This. Log ("getlevel1approver:" + level1user );//Write debugging logs
This. setvariable ("level1approver", level1user );//Set Variables
//Get Field Value
Spfielduservalue user2value = cfgitem. Fields. getfield ("level2approver"). getfieldvalue (cfgitem ["level2approver"]. tostring () as spfielduservalue;
VaR level2user = user2value. User. loginname;
This. Log ("getlevel2approver:" + level2user );
This. setvariable ("level2approver", level2user );
Workflow:
Add variable:
Code:
Note:
If you have the ability to write in a custom formCodeTry to pass the required data into the workflow variables before submitting the code-written form.
If an error occurs while executing code in the workflow, the entire workflow fails and cannot be recovered. Only the process can be restarted.