Difference between revisions of "DCS Using Script"

From Catglobe Wiki
Jump to: navigation, search
 
(21 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
[[Category:Answer_sheet_data_caches]]
 
[[Category:Answer_sheet_data_caches]]
  
 +
=DCS Using Script=
  
 +
== <span style="color:#DF8621">'''Overview'''</span> ==
 +
 +
DCS now can have data without using questionnaire, it's setting by script:
  
 
[[File:2018-10-23_11-04-50.png]]
 
[[File:2018-10-23_11-04-50.png]]
  
DCS using with script, required a workflow. The workflow get 5 parameters:
 
  
1: Any parameter you have specified in the setup
+
DCS using with script, required a workflow:
 +
 
 +
- The workflow must return [[CustomDataCacheSpecificationBuildResult class|CustomDataCacheSpecificationBuildResult]] with UniqueIds and NonUniqueIds
 +
 
 +
- The workflow get 5 parameters:
  
2: The DateTime (or Empty) from which to include data in a partial rebuild
+
* 1: Any parameter you have specified in the setup
  
3: The Entire array of Non Unique Ids from last rebuild (or empty if full rebuild)
+
* 2: The DateTime (or Empty) from which to include data in a partial rebuild
  
4: The Entire array of Unique Ids from last rebuild (or empty if full rebuild)
+
* 3: The Entire array of Non Unique Ids from last rebuild (or empty if full rebuild)
  
5: The extraParameter, can be set when the rebuild is instanciated from cgscript
+
* 4: The Entire array of Unique Ids from last rebuild (or empty if full rebuild)
  
And must return CustomDataCacheSpecificationBuildResult
+
* 5: The extraParameter, can be set when the rebuild is instanciated from cgscript
  
The first parameter can be set on UI or by cgscript
+
The first parameter can be set on UI:
  
 
[[File:2018-10-23_12-20-06.png]]
 
[[File:2018-10-23_12-20-06.png]]
  
Or can set by cgscript:
+
 
 +
Or can be set by cgscript:
 
<source lang="javascript">
 
<source lang="javascript">
Dictionary d1 = {"Key1":1, "Key2": 2};
+
Dictionary d1 = {"Key1":99, "Key2": "xxx"};
Dictionary d2 = {"": "xxxx"};
+
Dictionary d2 = {"": "yyy"};
 
DataCacheSpecification dcs = new DataCacheSpecification(dcsRId);
 
DataCacheSpecification dcs = new DataCacheSpecification(dcsRId);
 
dcs.BuildUsingWorkflowScriptResourceId = workflowRId;
 
dcs.BuildUsingWorkflowScriptResourceId = workflowRId;
//dcs.BuildUsingWorkflowScriptParameter=1;// number
+
dcs.BuildUsingWorkflowScriptParameter={d1,d2};
//dcs.BuildUsingWorkflowScriptParameter="xyz"; // string
 
//dcs.BuildUsingWorkflowScriptParameter={"xyz",1};// array of string and number
 
dcs.BuildUsingWorkflowScriptParameter={d1,d2};// array of Dictionary
 
 
dcs.Save();
 
dcs.Save();
 
</source>
 
</source>
  
The fifth parameter can be set when rebuild DCS
+
The fifth parameter can be set when rebuild DCS, see more on the dcs.Rebuild on [[DataCacheSpecification class|DCS class]]
 
<source lang="javascript">
 
<source lang="javascript">
dcs.Rebuild(true, true, 0, true, "abc");
+
dcs.Rebuild(true, true, 0, true, extraParameter);
 
</source>
 
</source>
  
Example for using script:
+
Note: ''Also support to select Ids and NonUniqueIds of DCS'':
 +
<source lang="javascript">
 +
selectMultiColumn(SYS_SCRIPT_NONUNIQUEID_SYS, SYS_SCRIPT_UNIQUEID_SYS) where true;
 +
</source>
  
A simple DCS with 5 rows and one column "test"; value for each row is a random number
+
== <span style="color:#DF8621">'''Example'''</span> ==
 +
 
 +
===<span style="color:#DF8621"> Example 1 </span>===
 +
 
 +
 
 +
A simple DCS with one column name "test" and 5 rows, value for each row is a random number. Like this:
  
 
[[File:2018-10-25_11-22-00.png]]
 
[[File:2018-10-25_11-22-00.png]]
Line 56: Line 69:
  
 
[[File:2018-10-25_11-29-38.png]]
 
[[File:2018-10-25_11-29-38.png]]
 +
  
 
- Create a workflow and insert the workflow in to the DCS
 
- Create a workflow and insert the workflow in to the DCS
Line 61: Line 75:
 
[[File:2018-10-25_11-40-05.png]]
 
[[File:2018-10-25_11-40-05.png]]
  
Code on workflow must return CustomDataCacheSpecificationBuildResult, how many rows on DCS belonging the length of res.
+
Code on workflow must return [[CustomDataCacheSpecificationBuildResult class|CustomDataCacheSpecificationBuildResult]], how many rows on DCS belonging the length of array Ids and NonUniqueIds.
 
In this example, res is returned with array 5 items, therefor the DCS have 5 rows
 
In this example, res is returned with array 5 items, therefor the DCS have 5 rows
  
Line 71: Line 85:
 
</source>
 
</source>
  
Let continue with another example using parameter
+
After rebuild DCS, we have the DCS like this:
 +
 
 +
[[File:2018-10-25_11-22-00.png]]
 +
===<span style="color:#DF8621"> Example 2 </span>===
 +
 
 +
 
 +
Add another column "Order" in to the above DCS, value for each row is a text: "Order number 1" to "Order number 5"
 +
 
 +
[[File:2018-10-26_10-34-42.png]]
 +
 
 +
How to do:
 +
 
 +
- Add custom column name "Order", type full column on the DCS:
 +
 
 +
[[File:2018-10-26_10-35-15.png]]
 +
 
 +
 
 +
Because on script of Order custom column, have an undefined variables x, therefore we can not create that Order column on UI, just make by cgscrip:
 +
 
 +
<source lang="javascript">
 +
DataCacheSpecification dcs = new DataCacheSpecification(15640179);
 +
QcsCustomColumn cc = new QcsCustomColumn("Order", "string", true, dcs);
 +
cc.CgScript = "array param = Workflow_getParameters();
 +
Dictionary localCache = param[0];
 +
FullCustomColumnSettings fs = param[1];
 +
array result = {};
 +
number numberRows = fs.UpdatedNumberOfRows;
 +
for(number i = 0; i < numberRows; i++) {
 +
 
 +
    result.Add(x + convertToString(i+1));
 +
}
 +
return result;";
 +
cc.Save();
 +
dcs.Save();
 +
</source>
 +
 
 +
( ''On the above script is used FullCustomColumnSettings for getting row number, see more the class [[FullCustomColumnSettings class|FullCustomColumnSettings]]'' )
 +
 
 +
- In workflow, add 1 more line to set value:
 +
 
 +
<source lang="javascript">
 +
res.AddVariableForFullCustomColumns("x", "Order number ");
 +
</source>
 +
 
 +
[[File:2018-10-26_10-36-36.png]]
 +
 
 +
 
 +
After rebuild the DCS, "x" will be replace by "Order number "
 +
 
 +
[[File:2018-10-26_10-34-42.png]]
 +
 
 +
 
 +
 
 +
===<span style="color:#DF8621"> Example 3 </span>===
 +
 
 +
Let add one more column order same with the column Order above, name "Order1"
 +
 
 +
[[File:2018-10-26_11-48-55.png]]
 +
 
 +
But this time row value will be set from parameter.
 +
 
 +
How to do:
 +
 
 +
- Put parameter on DCS:
 +
 
 +
[[File:2018-10-26_12-00-04.png]]
 +
 
 +
 
 +
- Create a full custom column name "Order1"
 +
 
 +
[[File:2018-10-26_11-56-05.png]]
 +
 
 +
- On workflow need adding code for get parameter
 +
<source lang="javascript">
 +
array param = Workflow_getParameters();// array param with 5 items
 +
array a = param[0];// array a with 1 item type dictionary
 +
Dictionary d = a[0];
 +
string value = d["key"];
 +
</source>
 +
 
 +
And also need add one line for setting value
 +
<source lang="javascript">
 +
res.AddVariableForFullCustomColumns("y", value );
 +
</source>
 +
 
 +
[[File:2018-10-26_12-04-45.png]]
 +
 
 +
 
 +
After rebuilding DCS, value for row will be replace "y" by value "Order number " which was wet from DCS parameter
 +
 
 +
[[File:2018-10-26_11-48-55.png]]
 +
 
 +
 
 +
 
 +
===<span style="color:#DF8621"> Example 4 </span>===
 +
 
 +
DCS can also get value while buiding DCS, by using the fifth parameter
 +
 
 +
Let make an example, add another column name "Date" to the DCS, value for each row is current dateTime when build DCS
 +
 
 +
[[File:2018-10-26_13-43-15.png]]
 +
 
 +
 
 +
How to do:
 +
 
 +
- First, add a full custom column name "Date"
 +
 
 +
[[File:2018-10-26_13-48-18.png]]
 +
 
 +
 
 +
- On workflow add a line to get the fifth parameter
 +
 
 +
<source lang="javascript">
 +
array extraParameter = param[4];
 +
</source>
 +
 
 +
And also add a line for set the parameter
 +
 
 +
<source lang="javascript">
 +
res.AddVariableForFullCustomColumns("z", extraParameter );
 +
</source>
 +
 
 +
[[File:2018-10-26_13-55-24.png]]
 +
 
 +
 
 +
- Values will be set when rebuild DCS by [[DataCacheSpecification class|dcs.Rebuild]]
 +
<source lang="javascript">
 +
DataCacheSpecification dcs = new DataCacheSpecification(DCSRid);
 +
array extraParameter = getCurrentDateTime();
 +
dcs.Rebuild(true, true, 0, true, extraParameter);
 +
</source>
 +
 
 +
 
 +
DCS will look like below after rebuiding:
 +
 
 +
[[File:2018-10-26_13-43-15.png]]

Latest revision as of 11:17, 26 October 2018


DCS Using Script

Overview

DCS now can have data without using questionnaire, it's setting by script:

2018-10-23 11-04-50.png


DCS using with script, required a workflow:

- The workflow must return CustomDataCacheSpecificationBuildResult with UniqueIds and NonUniqueIds

- The workflow get 5 parameters:

  • 1: Any parameter you have specified in the setup
  • 2: The DateTime (or Empty) from which to include data in a partial rebuild
  • 3: The Entire array of Non Unique Ids from last rebuild (or empty if full rebuild)
  • 4: The Entire array of Unique Ids from last rebuild (or empty if full rebuild)
  • 5: The extraParameter, can be set when the rebuild is instanciated from cgscript

The first parameter can be set on UI:

2018-10-23 12-20-06.png


Or can be set by cgscript:

Dictionary d1 = {"Key1":99, "Key2": "xxx"};
Dictionary d2 = {"": "yyy"};
DataCacheSpecification dcs = new DataCacheSpecification(dcsRId);
dcs.BuildUsingWorkflowScriptResourceId = workflowRId;
dcs.BuildUsingWorkflowScriptParameter={d1,d2};
dcs.Save();

The fifth parameter can be set when rebuild DCS, see more on the dcs.Rebuild on DCS class

dcs.Rebuild(true, true, 0, true, extraParameter);

Note: Also support to select Ids and NonUniqueIds of DCS:

selectMultiColumn(SYS_SCRIPT_NONUNIQUEID_SYS, SYS_SCRIPT_UNIQUEID_SYS) where true;

Example

Example 1

A simple DCS with one column name "test" and 5 rows, value for each row is a random number. Like this:

2018-10-25 11-22-00.png

How to do it:

- Create a new DCS:

+ Choose using script

+ Add a custom column

2018-10-25 11-29-38.png


- Create a workflow and insert the workflow in to the DCS

2018-10-25 11-40-05.png

Code on workflow must return CustomDataCacheSpecificationBuildResult, how many rows on DCS belonging the length of array Ids and NonUniqueIds. In this example, res is returned with array 5 items, therefor the DCS have 5 rows

CustomDataCacheSpecificationBuildResult res = new CustomDataCacheSpecificationBuildResult();
res.NonUniqueIds.AddRange({1,2,3,4,5});
res.Ids.AddRange({5,6,7,8,9});
return res;

After rebuild DCS, we have the DCS like this:

2018-10-25 11-22-00.png

Example 2

Add another column "Order" in to the above DCS, value for each row is a text: "Order number 1" to "Order number 5"

2018-10-26 10-34-42.png

How to do:

- Add custom column name "Order", type full column on the DCS:

2018-10-26 10-35-15.png


Because on script of Order custom column, have an undefined variables x, therefore we can not create that Order column on UI, just make by cgscrip:

DataCacheSpecification dcs = new DataCacheSpecification(15640179);
QcsCustomColumn cc = new QcsCustomColumn("Order", "string", true, dcs);
cc.CgScript = "array param = Workflow_getParameters();
Dictionary localCache = param[0];
FullCustomColumnSettings fs = param[1];
array result = {};
number numberRows = fs.UpdatedNumberOfRows;
for(number i = 0; i < numberRows; i++) {

    result.Add(x + convertToString(i+1));
}
return result;";
cc.Save();
dcs.Save();

( On the above script is used FullCustomColumnSettings for getting row number, see more the class FullCustomColumnSettings )

- In workflow, add 1 more line to set value:

res.AddVariableForFullCustomColumns("x", "Order number ");

2018-10-26 10-36-36.png


After rebuild the DCS, "x" will be replace by "Order number "

2018-10-26 10-34-42.png


Example 3

Let add one more column order same with the column Order above, name "Order1"

2018-10-26 11-48-55.png

But this time row value will be set from parameter.

How to do:

- Put parameter on DCS:

2018-10-26 12-00-04.png


- Create a full custom column name "Order1"

2018-10-26 11-56-05.png

- On workflow need adding code for get parameter

array param = Workflow_getParameters();// array param with 5 items
array a = param[0];// array a with 1 item type dictionary 
Dictionary d = a[0];
string value = d["key"];

And also need add one line for setting value

res.AddVariableForFullCustomColumns("y", value );

2018-10-26 12-04-45.png


After rebuilding DCS, value for row will be replace "y" by value "Order number " which was wet from DCS parameter

2018-10-26 11-48-55.png


Example 4

DCS can also get value while buiding DCS, by using the fifth parameter

Let make an example, add another column name "Date" to the DCS, value for each row is current dateTime when build DCS

2018-10-26 13-43-15.png


How to do:

- First, add a full custom column name "Date"

2018-10-26 13-48-18.png


- On workflow add a line to get the fifth parameter

array extraParameter = param[4];

And also add a line for set the parameter

res.AddVariableForFullCustomColumns("z", extraParameter );

2018-10-26 13-55-24.png


- Values will be set when rebuild DCS by dcs.Rebuild

DataCacheSpecification dcs = new DataCacheSpecification(DCSRid);
array extraParameter = getCurrentDateTime();
dcs.Rebuild(true, true, 0, true, extraParameter);


DCS will look like below after rebuiding:

2018-10-26 13-43-15.png