Difference between revisions of "WorkflowScript class"
Line 27: | Line 27: | ||
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>CgScript</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>The script.</nowiki>}} | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>CgScript</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>The script.</nowiki>}} | ||
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>DataCache</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set the DataCache under which to run the script under. 0 means clear setting. Only for tabulation scripts.</nowiki>}} | {{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>DataCache</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set the DataCache under which to run the script under. 0 means clear setting. Only for tabulation scripts.</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>DynamicScriptName</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Script name to use for error messages in dynamic scripts.</nowiki>}} | ||
{{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>EnableProfiling</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Set to true to enable profiling.</nowiki>}} | {{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>EnableProfiling</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Set to true to enable profiling.</nowiki>}} | ||
{{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>ImpersonatedUser</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>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.</nowiki>}} | {{CGscriptProperties_Template|ReturnType=int|Name=<nowiki>ImpersonatedUser</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>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.</nowiki>}} |
Latest revision as of 08:20, 12 December 2024
WorkflowScript
Class to manipulate workflows.
Parent class
Inherits from object
Constructors
- (int 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
- object Call(params AnyType) - Run the script with the given arguments
- object 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.", int 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.
- int Schedule(CatTaskSchedule schedule "When to run", bool informMe "Send mail when finished task", array parameters "Send mail when finished task") - Schedule workflow to run at a given schedule. Returns CatTask instance id
- (From object) 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; set; } - The script.
- int DataCache { get; set; } - Get/Set the DataCache under which to run the script under. 0 means clear setting. Only for tabulation scripts.
- string DynamicScriptName { get; set; } - Script name to use for error messages in dynamic scripts.
- bool EnableProfiling { get; set; } - Set to true to enable profiling.
- int 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.
- ProfilingResult ProfilingResult { get; } - Returns the result of the Profiling.
- int Questionnaire { get; set; } - Get/Set the Questionnaire under which to run the script under. 0 means clear setting. Only for non-tabulation scripts.
- (From object) TypeInformation TypeInformation { get; } - Get information about this class.
- int UniqueId { get; } - The resource id of the workflow.
Notes
To be able to run the dynamic scripts, means using the second constructor of this class. Users must have this special navigation access in both module "Workflow Module" and "Tabulation Script Module": Able to create scripts that can dynamically create scripts. This special navigation access just can be seen and set by user Administrator.
Examples
Ex 1:
/*
* MAKE A COPY OF A SPECIFIED WORKFLOW
*/
/* Input Parameters for this workflow */
// Required - Set values here
number sourceWorkflowRID;
string nameOfCopy;
number parentResourceId;
/* Other variables */
bool isTabulation;
string CgScript;
bool BatchMode;
number ImpersonatedUser;
number Questionnaire;
number DataCache;
object error;
/* Checking the required parameters */
if(sourceWorkflowRID == empty) {
print("Please set value for parameter: sourceWorkflowRID. Workflow failed.");
return;
}
if(nameOfCopy == empty) {
print("Please set value for parameter: nameOfCopy. 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(sourceWorkflowRID);
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 = source.DataCache;
try
// because this property is not available for Tabulation Script in 581 version
ImpersonatedUser = source.ImpersonatedUser;
catch(error) {}
dest = new WorkflowScript(CgScript, true);
dest.DataCache = DataCache;
try
// because this property is not available for Tabulation Script in 581 version
dest.ImpersonatedUser = ImpersonatedUser;
catch(error) {}
// Save the copied one
dest.Save(nameOfCopy, parentResourceId);
print("Completed! The resource id of new copied one: " + dest.UniqueId);
return dest;
}
// The source is non-Tabulation Script
else {
// Get all properties of this non-Tabulation Script
CgScript = source.CgScript;
Questionnaire = source.Questionnaire;
BatchMode = source.BatchMode;
ImpersonatedUser = source.ImpersonatedUser;
dest = new WorkflowScript(CgScript, false);
dest.Questionnaire = Questionnaire;
dest.BatchMode = BatchMode;
dest.ImpersonatedUser = ImpersonatedUser;
// Save the copied one
dest.Save(nameOfCopy, parentResourceId);
print("Completed! The resource id of new copied one: " + dest.UniqueId);
return dest;
}
Ex 2:
ProfilingResult pr;
WorkflowScript wf = new WorkflowScript(11951195);
pr = wf.ProfilingResult;
pr.EnableProfiling = true;
wf.Call();
print(pr.Script); // {print("hello world");}
print(pr.CompileTime); // 0.0595
print(pr.CountResult); // {"1": {"4": 1}}
print(pr.DependencyGraphTime); // 0
print(pr.TimeResult); // {"1": {"-1": 0.0034, "4": 0.0034}}
print(pr.WhereExpTime); // 0
Example for schedule a workflow
//wS.Schedule(schedule, informMe, parameters)
number workflowRId = 15562503;
WorkflowScript wS = new WorkflowScript(workflowRId);
DateTime dt = new DateTime("2017/05/31 03:10");
CatTaskSpecificTimeSchedule schedule = new CatTaskSpecificTimeSchedule(dt);
//CatTaskInstantSchedule schedule = new CatTaskInstantSchedule();
bool informMe = false;
array parameters={};
wS.Schedule(schedule, informMe, parameters);//Returns CatTask instance id: 104700 (CatTaskMetaDataId: 54183)