The executecode activity is added to the latest version of quickflow. You can also write the executecode by using the designer design process.CodeLogic.
Executecode activity attributes:
Usercontext: Specifies whether the code runs as the initiator or system account.
Methodcode: code to be run. Double-click the activity to bring up the code editing window.
Methodparam: parameter, which can be accessed directly through Param in the code.
Executecode implementation principle:
Executecode is implemented by dynamic code compilation. You can specify the implementation code of a method. quickflow will compile the method code into a dynamicclass, as shown below:
Using system. collections. generic; using system. LINQ; using system. text; using system. workflow. componentmodel; using Microsoft. sharePoint; using Microsoft. sharepoint. workflow; using Microsoft. sharepoint. workflowactions; using codeart. sharepoint. camlquery; // methodusingnamespace dynamiccodegenerate {public class dynamicclass: quickflow. dynamicclasstemplate {public dynamicclass (activity root, spworkflowactivationproperties P): Base (root, p) {} protected override void execute (string PARAM) {// dllref // using codeart. sharepoint. camlquery; // methodcode ;}}}";
The user code is inserted to the // methodcode location.
Basic Method
The base class of dynamicclass has implemented a large number of common methods and can be called directly:
Basic Attributes and Methods
| Spweb |
Obtain the current spweb |
| Splistitem item |
Obtain the current listitem |
| Protected splist list |
Obtain the current list |
| Void log (Object MSG) |
Write logs. The log information is displayed on the workflow status page. |
| Object getvariable (string name) |
Get workflow variable value |
| Void setvariable (string name, object V) |
Set workflow variable values |
| |
|
List item Operation Method
| Splistitem getitem (string listname, int Itemid) |
Get list items |
| Splistitemcollection getitems (string listname, camlexpression expr) |
Query list items |
| Void updateitem (string fieldnames, Params object [] values) |
Update list items |
| Void updateitem (string listname, int Itemid, string fieldnames, Params object [] values) |
|
| Updateitem (string listname, int Itemid, hashtable properties) |
|
| Int createitem (string listname, hashtable properties) |
Create a list item |
| Int createitem (string listname, string fieldnames, Params object [] values) |
|
Void deleteitem (string listname, int Itemid) |
Delete list items |
Void deleteitems (string listname, camlexpression expr) |
Delete a list item that meets the criteria |
| Void setmoderationstatus (string listname, int Itemid, spmoderationstatustype type, string comments) |
Set Content Approval Status |
| Void setmoderationstatus (spmoderationstatustype type, string comments) |
Set the Content Approval Status of the current project |
For the implementation of quickflow. dynamicclasstemplate, see:
Http://cid-7f5a25cdf47d03e6.office.live.com/self.aspx/QuickFlow/FrameworkCode/DynamicClassTemplate.cs
Http://cid-7f5a25cdf47d03e6.office.live.com/self.aspx/QuickFlow/FrameworkCode/DynamicClassTemplate.ListItem.cs
In addition to the methods provided above, you can write any C # code
Note:
1) We recommend that you only use executecode in QFD. If you use Vs + QF, you can directly process the related events provided by quickflow (such as completed) or use step + codeactivity to better implement code functions.
2) When using a custom form, the code should be written to the form or business logic layer first.
3) to reference other DLL or namespaces, the code format is as follows:
// Dllref some. dll
// Using XXX. XXX;
... Other code
DLL needs to be deployed to GAC first
Example:
How to obtain other list data through executecode.
Scenario: A Configuration list is provided 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:
Create a workflow and add two string workflow variables: level1approver and level2approver.
Drag an executecode activity and two Task activities. The user attribute of the task activity is bound to level1approver and level2approver respectively.
Draw line connection start-> ExecuteCode-Task1-> task2.
Double-click executecode and write the script as follows:
Queryfield titlefield = new queryfield ("title ");
Splist cfglist = This. Web. Lists ["approver configuration"];
VaR cfgitem = listquery. From (cfglist). Where (titlefield = ""). getitems () [0]; // get the configuration item
// Obtain the field value
Spfielduservalue user1value = cfgitem. Fields. getfield ("level1approver"). getfieldvalue (cfgitem ["level1approver"]. tostring () as spfielduservalue;
VaR level1user = user1value. User. loginname;
This. Log ("getlevel1approver:" + level1user );
This. setvariable ("level1approver", level1user );
// Obtain the 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 );
Complete post: http://www.cnblogs.com/jianyi0115/archive/2013/05/14/3077140.html