Difference between revisions of "WorkflowScript class"

From Catglobe Wiki
Jump to: navigation, search
Line 1: Line 1:
 
{{CGscriptClass_Template
 
{{CGscriptClass_Template
|Name=<nowiki>WorkflowScript</nowiki>
+
|Name=WorkflowScript
|Description=<nowiki>Class to manipulate workflows.</nowiki>
+
|Description=Class to manipulate workflows.
 
|Constructors=
 
|Constructors=
 
{{CGscriptConstructors_Template|Parameters=
 
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=number|Name=<nowiki>resourceId</nowiki>|Description=<nowiki>Resource id of the script to load</nowiki>}}
+
{{CGscriptParameters_Template|Type=number|Name=resourceId|Description=Resource id of the script to load}}
|Description=<nowiki>Load existing workflow</nowiki>}}
+
|Description=Load existing workflow}}
 
{{CGscriptConstructors_Template|Parameters=
 
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>script</nowiki>|Description=<nowiki>The script to use.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=<nowiki>isTabulation</nowiki>|Description=<nowiki>Set if this is a tabulation script or not</nowiki>}}
+
{{CGscriptParameters_Template|Type=string|Name=script|Description=The script to use.|Comma=,}}{{CGscriptParameters_Template|Type=bool|Name=isTabulation|Description=Set if this is a tabulation script or not}}
|Description=<nowiki>Make new workflow</nowiki>}}
+
|Description=Make new workflow}}
 
|Methods=
 
|Methods=
{{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>Call</nowiki>|Parameters={{CGscriptParameters_Template|Type=params AnyType|Name=params AnyType|Description=}}
+
{{CGscriptMethods_Template|ReturnType=AnyType|Name=Call|Parameters={{CGscriptParameters_Template|Type=params AnyType|Name=params AnyType|Description=}}
|Description=<nowiki>Run the script with the given arguments</nowiki>}}
+
|Description=Run the script with the given arguments}}
{{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>Invoke</nowiki>|Parameters=
+
{{CGscriptMethods_Template|ReturnType=AnyType|Name=Invoke|Parameters=
{{CGscriptParameters_Template|Type=array|Name=<nowiki>arguments</nowiki>|Description=<nowiki>The arguments to the script</nowiki>}}
+
{{CGscriptParameters_Template|Type=array|Name=arguments|Description=The arguments to the script}}
|Description=<nowiki>Run the script with the given arguments</nowiki>}}
+
|Description=Run the script with the given arguments}}
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Save</nowiki>|Parameters=
+
{{CGscriptMethods_Template|ReturnType=Empty|Name=Save|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>name</nowiki>|Description=<nowiki>Name of the resource. If empty it will not change the existing name. Required for new scripts.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=number|Name=<nowiki>parentResourceId</nowiki>|Description=<nowiki>Parent of the resource. If 0 it will not change the existing. Required for new scripts.</nowiki>}}
+
{{CGscriptParameters_Template|Type=string|Name=name|Description=Name of the resource. If empty it will not change the existing name. Required for new scripts.|Comma=,}}{{CGscriptParameters_Template|Type=number|Name=parentResourceId|Description=Parent of the resource. If 0 it will not change the existing. Required for new scripts.}}
|Description=<nowiki>Save the current workflowscript.</nowiki>}}
+
|Description=Save the current workflowscript.}}
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Save</nowiki>|Description=<nowiki>Save the current workflowscript using the existing name and parent.</nowiki>}}
+
{{CGscriptMethods_Template|ReturnType=Empty|Name=Save|Description=Save the current workflowscript using the existing name and parent.}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
+
{{CGscriptMethods_Template|ReturnType=string|Name=ToString|Description=The string representation of the object.}}
 
|Properties=
 
|Properties=
{{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>BatchMode</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set the if the non-tabulation script should run in batch mode.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=bool|Name=BatchMode|HasGetter=1|HasSetter=1|Description=Get/Set the if the non-tabulation script should run in batch mode.}}
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>CgScript</nowiki>|HasGetter=1|Description=<nowiki>The script.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=string|Name=CgScript|HasGetter=1|HasSetter=1|Description=The script.}}
{{CGscriptProperties_Template|ReturnType=number|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=number|Name=DataCache|HasGetter=1|HasSetter=1|Description=Get/Set the DataCache under which to run the script under. 0 means clear setting. Only for tabulation scripts.}}
{{CGscriptProperties_Template|ReturnType=number|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=bool|Name=EnableProfiling|HasGetter=1|HasSetter=1|Description=Set to true to enable profiling.}}
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=number|Name=ImpersonatedUser|HasGetter=1|HasSetter=1|Description=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.}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Questionnaire</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get/Set the Questionnaire under which to run the script under. 0 means clear setting. Only for non-tabulation scripts.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=string|Name=ObjectTypeName|HasGetter=1|Description=The name of the type of object.}}
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=ProfilingResult|Name=ProfilingResult|HasGetter=1|Description=Returns the result of the Profiling.}}
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>UniqueId</nowiki>|HasGetter=1|Description=<nowiki>The resource id of the workflow.</nowiki>}}
+
{{CGscriptProperties_Template|ReturnType=number|Name=Questionnaire|HasGetter=1|HasSetter=1|Description=Get/Set the Questionnaire under which to run the script under. 0 means clear setting. Only for non-tabulation scripts.}}
 +
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=TypeInformation|HasGetter=1|Description=Get information about this class.}}
 +
{{CGscriptProperties_Template|ReturnType=number|Name=UniqueId|HasGetter=1|Description=The resource id of the workflow.}}
 
}}
 
}}
  
==== <span style="color:#a52a2a;">'''Examples'''</span>  ====
+
=== '''Examples''' = ===
<source lang=javascript>
+
 
 +
'''Ex 1:''' <source lang="javascript">
 
/*
 
/*
  *   MAKE A COPY OF A SPECIFIED WORKFLOW
+
  * MAKE A COPY OF A SPECIFIED WORKFLOW
 
  */
 
  */
  
Line 41: Line 44:
 
number sourceWorkflowRID;
 
number sourceWorkflowRID;
 
string nameOfCopy;
 
string nameOfCopy;
number parentResourceId;  
+
number parentResourceId;  
  
 
/* Other variables */
 
/* Other variables */
Line 54: Line 57:
 
/* Checking the required parameters */
 
/* Checking the required parameters */
 
if(sourceWorkflowRID == empty) {
 
if(sourceWorkflowRID == empty) {
print("Please set value for parameter: sourceWorkflowRID. Workflow failed.");
+
print("Please set value for parameter: sourceWorkflowRID. Workflow failed.");
return;
+
return;
 
}
 
}
 
if(nameOfCopy == empty) {
 
if(nameOfCopy == empty) {
print("Please set value for parameter: nameOfCopy. Workflow failed.");
+
print("Please set value for parameter: nameOfCopy. Workflow failed.");
return;
+
return;
 
}
 
}
 
if(parentResourceId == empty) {
 
if(parentResourceId == empty) {
print("Please set value for parameter: parentResourceId. Workflow failed.");
+
print("Please set value for parameter: parentResourceId. Workflow failed.");
return;
+
return;
 
}
 
}
  
Line 72: Line 75:
 
// Check that the source is Tabulation Script or non-Tabulation Script
 
// Check that the source is Tabulation Script or non-Tabulation Script
 
try {
 
try {
if(source.DataCache != empty) // if throw error then the source is non-tabulation script
+
if(source.DataCache != empty) // if throw error then the source is non-tabulation script
isTabulation = true;
+
isTabulation = true;
 
}
 
}
 
catch(error){
 
catch(error){
// so the source is non-tabulation script
+
// so the source is non-tabulation script
isTabulation = false;
+
isTabulation = false;
 
}
 
}
  
Line 83: Line 86:
 
// The source is Tabulation Script
 
// The source is Tabulation Script
 
{
 
{
// Get all properties of this Tabulation Script
+
// Get all properties of this Tabulation Script
CgScript = source.CgScript;
+
CgScript = source.CgScript;
DataCache = source.DataCache;
+
DataCache = source.DataCache;
  
try  
+
try  
// because this property is not available for Tabulation Script in 581 version
+
// because this property is not available for Tabulation Script in 581 version
ImpersonatedUser = source.ImpersonatedUser;
+
ImpersonatedUser = source.ImpersonatedUser;
catch(error) {}
+
catch(error) {}
+
  
    dest = new WorkflowScript(CgScript, true);
+
dest = new WorkflowScript(CgScript, true);
dest.DataCache = DataCache;
+
dest.DataCache = DataCache;
+
try  
+
try  
// because this property is not available for Tabulation Script in 581 version
+
// because this property is not available for Tabulation Script in 581 version
dest.ImpersonatedUser = ImpersonatedUser;
+
dest.ImpersonatedUser = ImpersonatedUser;
catch(error) {}
+
catch(error) {}
+
// Save the copied one
+
// Save the copied one
dest.Save(nameOfCopy, parentResourceId);
+
dest.Save(nameOfCopy, parentResourceId);
+
print("Completed! The resource id of new copied one: " + dest.UniqueId);
+
print("Completed! The resource id of new copied one: " + dest.UniqueId);  
+
return dest;
+
return dest;
 
}  
 
}  
 
// The source is non-Tabulation Script
 
// The source is non-Tabulation Script
 
else {
 
else {
// Get all properties of this non-Tabulation Script
+
// Get all properties of this non-Tabulation Script
CgScript = source.CgScript;
+
CgScript = source.CgScript;
Questionnaire = source.Questionnaire;
+
Questionnaire = source.Questionnaire;
BatchMode = source.BatchMode;
+
BatchMode = source.BatchMode;
ImpersonatedUser = source.ImpersonatedUser;
+
ImpersonatedUser = source.ImpersonatedUser;
+
    dest = new WorkflowScript(CgScript, false);
+
dest = new WorkflowScript(CgScript, false);
dest.Questionnaire = Questionnaire;
+
dest.Questionnaire = Questionnaire;
dest.BatchMode = BatchMode;
+
dest.BatchMode = BatchMode;
dest.ImpersonatedUser = ImpersonatedUser;
+
dest.ImpersonatedUser = ImpersonatedUser;
  
// Save the copied one
+
// Save the copied one
dest.Save(nameOfCopy, parentResourceId);
+
dest.Save(nameOfCopy, parentResourceId);
+
print("Completed! The resource id of new copied one: " + dest.UniqueId);
+
print("Completed! The resource id of new copied one: " + dest.UniqueId);  
+
return dest;
+
return dest;
 
}
 
}
 
</source>
 
</source>

Revision as of 13:01, 17 October 2013

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; set; } - 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.
  • bool EnableProfiling { get; set; } - Set to true to enable profiling.
  • 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.
  • ProfilingResult ProfilingResult { get; } - Returns the result of the Profiling.
  • 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 =

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;
}