Difference between revisions of "DCS Using Script"
Line 111: | Line 111: | ||
[[File:2018-10-26_10-34-42.png]] | [[File:2018-10-26_10-34-42.png]] | ||
+ | |||
+ | 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 gotten from parameter | ||
+ | |||
+ | [[File:2018-10-26_12-00-04.png]] | ||
+ | |||
+ | Also need use cgscript to create full custom column "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 alse need add one line for setting value | ||
+ | <source lang="javascript"> | ||
+ | res.AddVariableForFullCustomColumns("y", value ); | ||
+ | </source> | ||
+ | |||
+ | |||
+ | [[File:2018-10-26_12-04-45.png]] |
Revision as of 06:09, 26 October 2018
DCS now can have data without questionnaire, it's setting by script
DCS using with script, required a workflow. 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
And must return CustomDataCacheSpecificationBuildResult
The first parameter can be set on UI or by cgscript
Or can set by cgscript:
Dictionary d1 = {"Key1":1, "Key2": 2};
Dictionary d2 = {"": "xxxx"};
DataCacheSpecification dcs = new DataCacheSpecification(dcsRId);
dcs.BuildUsingWorkflowScriptResourceId = workflowRId;
//dcs.BuildUsingWorkflowScriptParameter=1;// number
//dcs.BuildUsingWorkflowScriptParameter="xyz"; // string
//dcs.BuildUsingWorkflowScriptParameter={"xyz",1};// array of string and number
dcs.BuildUsingWorkflowScriptParameter={d1,d2};// array of Dictionary
dcs.Save();
The fifth parameter can be set when rebuild DCS
dcs.Rebuild(true, true, 0, true, "abc");
Example for using script:
A simple DCS with 5 rows and one column "test"; value for each row is a random number
How to do it:
- Create a new DCS:
+ Choose using script
+ Add a custom column
- Create a workflow and insert the workflow in to the DCS
Code on workflow must return CustomDataCacheSpecificationBuildResult, how many rows on DCS belonging the length of res. 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;
Let continue with another example using parameter Add another column "Order" in to the above DCS, value for each row is a text: "Order number 1" to "Order number 5"
Add custom column name "Order", type full column on the DCS:
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();
In workflow, add 1 more line:
res.AddVariableForFullCustomColumns("x", "Order number ");
After rebuild the DCS, "x" will be replace by "Order number "
Let add one more column order same with the column Order above, name "Order1"
But this time row value will be gotten from parameter
Also need use cgscript to create full custom column "Order1"
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 alse need add one line for setting value
res.AddVariableForFullCustomColumns("y", value );