Difference between revisions of "WorkflowScript class"
Line 32: | Line 32: | ||
==== <span style="color:#a52a2a;">'''Examples'''</span> ==== | ==== <span style="color:#a52a2a;">'''Examples'''</span> ==== | ||
+ | <source lang=javascript> | ||
+ | /* | ||
+ | * MAKE A COPY OF A SPECIFIED WORKFLOW | ||
+ | */ | ||
+ | |||
+ | /* Input Parameters for this workflow */ | ||
+ | // Required - Set values here | ||
+ | number inputWorkflow_RID; | ||
+ | string nameOfTheCopy; | ||
+ | number parentResourceId; | ||
+ | |||
+ | /* Other variables */ | ||
+ | bool isTabulation; | ||
+ | string CgScript; | ||
+ | bool BatchMode; | ||
+ | number ImpersonatedUser_RID; | ||
+ | number Questionnaire_RID; | ||
+ | number DataCache_RID; | ||
+ | object error; | ||
+ | |||
+ | /* Checking the required parameters */ | ||
+ | if(inputWorkflow_RID == empty) { | ||
+ | print("Please set value for parameter: inputWorkflow_RID. Workflow failed."); | ||
+ | return; | ||
+ | } | ||
+ | if(nameOfTheCopy == empty) { | ||
+ | print("Please set value for parameter: nameOfTheCopy. Workflow failed."); | ||
+ | return; | ||
+ | } | ||
+ | if(parentResourceId == empty) { | ||
+ | print("Please set value for parameter: parentResourceId. Workflow failed."); | ||
+ | return; | ||
+ | } | ||
+ | |||
+ | /* Now doing the job: Making the copy */ | ||
+ | object source = new WorkflowScript(inputWorkflow_RID); | ||
+ | object dest; | ||
+ | |||
+ | // Check that the source is Tabulation Script or non-Tabulation Script | ||
+ | try { | ||
+ | if(source.DataCache != empty) // if throw error then the source is non-tabulation script | ||
+ | isTabulation = true; | ||
+ | } | ||
+ | catch(error){ | ||
+ | // so the source is non-tabulation script | ||
+ | isTabulation = false; | ||
+ | } | ||
+ | |||
+ | if(isTabulation == true) | ||
+ | // The source is Tabulation Script | ||
+ | { | ||
+ | // Get all properties of this Tabulation Script | ||
+ | CgScript = source.CgScript; | ||
+ | DataCache_RID = source.DataCache; | ||
+ | |||
+ | dest = new WorkflowScript(CgScript, true); | ||
+ | dest.DataCache = DataCache_RID; | ||
+ | |||
+ | // Save the copied one | ||
+ | dest.Save(nameOfTheCopy, parentResourceId); | ||
+ | |||
+ | print("Completed! The resource if of new copyied one: " + dest.UniqueId); | ||
+ | |||
+ | return dest; | ||
+ | } | ||
+ | // The source is non-Tabulation Script | ||
+ | else { | ||
+ | // Get all properties of this non-Tabulation Script | ||
+ | CgScript = source.CgScript; | ||
+ | Questionnaire_RID = source.Questionnaire; | ||
+ | BatchMode = source.BatchMode; | ||
+ | |||
+ | dest = new WorkflowScript(CgScript, false); | ||
+ | dest.Questionnaire = Questionnaire_RID; | ||
+ | dest.BatchMode = BatchMode; | ||
+ | |||
+ | // Save the copied one | ||
+ | dest.Save(nameOfTheCopy, parentResourceId); | ||
+ | |||
+ | print("Completed! The resource if of new copyied one: " + dest.UniqueId); | ||
+ | |||
+ | return dest; | ||
+ | } | ||
+ | </source> |
Revision as of 12:06, 17 February 2012
WorkflowScript
Class to manipulate workflows.
Constructors
- (number resourceId "Resource id of the script to load") - Load existing workflow
- (string script "The script to use.", bool isTabulation "Set if this is a tabulation script or not") - Make new workflow
Methods
- AnyType Call(params AnyType) - Run the script with the given arguments
- AnyType Invoke(array arguments "The arguments to the script") - Run the script with the given arguments
- Empty Save(string name "Name of the resource. If empty it will not change the existing name. Required for new scripts.", number parentResourceId "Parent of the resource. If 0 it will not change the existing. Required for new scripts.") - Save the current workflowscript.
- Empty Save() - Save the current workflowscript using the existing name and parent.
- string ToString() - The string representation of the object.
Properties
- bool BatchMode { get; set; } - Get/Set the if the non-tabulation script should run in batch mode.
- string CgScript { get; } - The script.
- number DataCache { get; set; } - Get/Set the DataCache under which to run the script under. 0 means clear setting. Only for tabulation scripts.
- number ImpersonatedUser { get; set; } - Get/Set the user under which to run the script under. Must have Full access to the user to set as impersonation. 0 means clear impersonation.
- string ObjectTypeName { get; } - The name of the type of object.
- number Questionnaire { get; set; } - Get/Set the Questionnaire under which to run the script under. 0 means clear setting. Only for non-tabulation scripts.
- TypeInformation TypeInformation { get; } - Get information about this class.
- number UniqueId { get; } - The resource id of the workflow.
Examples
/*
* MAKE A COPY OF A SPECIFIED WORKFLOW
*/
/* Input Parameters for this workflow */
// Required - Set values here
number inputWorkflow_RID;
string nameOfTheCopy;
number parentResourceId;
/* Other variables */
bool isTabulation;
string CgScript;
bool BatchMode;
number ImpersonatedUser_RID;
number Questionnaire_RID;
number DataCache_RID;
object error;
/* Checking the required parameters */
if(inputWorkflow_RID == empty) {
print("Please set value for parameter: inputWorkflow_RID. Workflow failed.");
return;
}
if(nameOfTheCopy == empty) {
print("Please set value for parameter: nameOfTheCopy. Workflow failed.");
return;
}
if(parentResourceId == empty) {
print("Please set value for parameter: parentResourceId. Workflow failed.");
return;
}
/* Now doing the job: Making the copy */
object source = new WorkflowScript(inputWorkflow_RID);
object dest;
// Check that the source is Tabulation Script or non-Tabulation Script
try {
if(source.DataCache != empty) // if throw error then the source is non-tabulation script
isTabulation = true;
}
catch(error){
// so the source is non-tabulation script
isTabulation = false;
}
if(isTabulation == true)
// The source is Tabulation Script
{
// Get all properties of this Tabulation Script
CgScript = source.CgScript;
DataCache_RID = source.DataCache;
dest = new WorkflowScript(CgScript, true);
dest.DataCache = DataCache_RID;
// Save the copied one
dest.Save(nameOfTheCopy, parentResourceId);
print("Completed! The resource if of new copyied one: " + dest.UniqueId);
return dest;
}
// The source is non-Tabulation Script
else {
// Get all properties of this non-Tabulation Script
CgScript = source.CgScript;
Questionnaire_RID = source.Questionnaire;
BatchMode = source.BatchMode;
dest = new WorkflowScript(CgScript, false);
dest.Questionnaire = Questionnaire_RID;
dest.BatchMode = BatchMode;
// Save the copied one
dest.Save(nameOfTheCopy, parentResourceId);
print("Completed! The resource if of new copyied one: " + dest.UniqueId);
return dest;
}