Sample script code for creating a workflow

This sample script code creates a workflow, creates the steps for the workflow, defines the routing order for the steps, assigns performers to the steps, and specifies validation rules for each step. There are two samples; one for creating an item workflow and one for creating a category workflow.

Sample script code for creating an item workflow

// create a catalog wfl: Initial --> Modify --> Success
	///////////////////////////////////////////////////////////
	var WFL_CATALOG1 = "wf-catalog1";
	var WFL= "Workflow";
	var WFL_COLLECTION1 = "wf collection1";

	var adminUsers = [];
	adminUsers[0] = "Admin";

 	workflow1 = new Workflow(WFL,"CATALOG"); 
 	workflow1.setWflAccessControlGroup("Default");
 	
	//create step 
  	var attributeCollections = [];
  	attributeCollections[0] = WFL_COLLECTION1;

  	step1 = workflow1.createWflStep("MODIFY", "Modify Step");
    	step1.setWflStepPerformerUsers(adminUsers);    
    	step1.setEditableAttributeGroups("ITEM_EDIT",attributeCollections);
    	step1.setEditableAttributeGroups("BULK_EDIT",attributeCollections);
    	step1.setWflStepReserveToEdit (true);
    	step1.setWflStepCategorizeEntries(true);

	//mapping: Initial --> Modify --> Success
 	workflow1.getWflInitialStep().mapWflStepExitValueToNextStep("SUCCESS", step1);
 	step1.mapWflStepExitValueToNextStep("DONE", "Success");
 	assertTrue(workflow1.saveWfl());

Sample script code for creating a category workflow

// create a catalog wfl: Initial --> Modify --> Success
	////////////////////////////////////////////////////////////
	var WFL_CATALOG1 = "wf-catalog1";
	var WFL= "Workflow";
	var WFL_COLLECTION1 = "wf collection1";

	var adminUsers = [];
	adminUsers[0] = "Admin";

 	workflow1 = new Workflow(WFL,"CATEGORY_TREE");
 	workflow1.setWflAccessControlGroup("Default");
 	
	//create step 
  	var attributeCollections = [];
  	attributeCollections[0] = WFL_COLLECTION1;

  	step1 = workflow1.createWflStep("MODIFY", "Modify Step");
    	step1.setWflStepPerformerUsers(adminUsers);    
    	step1.setEditableAttributeGroups("ITEM_EDIT",attributeCollections);
    	step1.setEditableAttributeGroups("BULK_EDIT",attributeCollections);
    	step1.setWflStepReserveToEdit (true);
    	step1.setWflStepCategorizeEntries(true);

	//mapping: Initial --> Modify --> Success
 	workflow1.getWflInitialStep().mapWflStepExitValueToNextStep("SUCCESS", step1);
 	step1.mapWflStepExitValueToNextStep("DONE", "Success");
 	assertTrue(workflow1.saveWfl());