RunQuery Script Examples: Difference between revisions
No edit summary |
No edit summary |
||
Line 50: | Line 50: | ||
</pre> | </pre> | ||
Following command | Following command gets list of cases for model id 123 and stores results to a datatable ''MyDataTable'' in project id 456: | ||
<pre> | <pre> | ||
(SELECT 'DataTableName', 'MyDataTable') UNION ALL | (SELECT 'DataTableName', 'MyDataTable') UNION ALL | ||
Line 87: | Line 87: | ||
"ModelId": 123 | "ModelId": 123 | ||
}') | }') | ||
--#RunQuery | |||
</pre> | |||
Following command gets list of events and stores results to a datatable ''MyDataTable'' in project id 456: | |||
<pre> | |||
(SELECT 'DataTableName', 'MyDataTable') UNION ALL | |||
(SELECT 'ProjectId', '456') UNION ALL | |||
(SELECT 'Configuration', '{ | |||
"Dimensions": null, | |||
"Values": [ | |||
{ | |||
"Name": "Case id", | |||
"Expression": "Case.Name" | |||
}, | |||
{ | |||
"Name": "Event type name", | |||
"Expression": "TypeName" | |||
}, | |||
{ | |||
"Name": "Time", | |||
"Expression": "Timestamp" | |||
}, | |||
{ | |||
"Name": "Difference from previous", | |||
"Expression": "(Timestamp-PreviousInCase.Timestamp)?.TotalDays" | |||
}, | |||
{ | |||
"Name": "Event index in case", | |||
"Expression": "IndexInCase+1" | |||
}, | |||
{ | |||
"Name": "Automation", | |||
"Expression": "Attribute(\"Automation\")" | |||
} | |||
], | |||
"Root": "Events", | |||
"ModelId": 123 | |||
} | |||
') | |||
--#RunQuery | --#RunQuery | ||
</pre> | </pre> |
Revision as of 15:45, 15 December 2021
This page contains script examples for the RunQuery script command. Note that single quotes (') in the Configuration parameter needs to be escaped by using two single quotes (usually expression queries don't contain single quotes).
Following command reads a datatable and stores it as a temporary table #MyTempTable in the scripting sandbox:
(SELECT 'TargetTable', '#MyTempTable') UNION ALL (SELECT 'Configuration', '{ "Root": "DatatableById(123).SqlDataFrame.Collect()" }') --#RunQuery
Following command reads filtered rows (Region is Dallas) from a datatable, and stores the result as a temporary table #MyTempTable in the scripting sandbox. The execution works efficiently as only the filtered rows are moved between the databases.
(SELECT 'TargetTable', '#MyTempTable') UNION ALL (SELECT 'Configuration', '{ "Root": "DatatableById(123).SqlDataFrame.Where(Column(\"Region\") == \"Dallas\").Collect()" }') --#RunQuery
Following command runs an expression query (dimensioning by Company Code attribute and calculate cases count for each for model id 123) and stores results to a temporary table MyTempTable in the scripting sandbox:
(SELECT 'TargetTable', '#MyTempTable') UNION ALL (SELECT 'Configuration', '{ "Dimensions": [ { "Name": "dimension0", "Expression": "Attribute(\"Company Code\")" } ], "Values": [ { "Name": "measure0", "Expression": "Count(_)", "AggregationExpression": "Sum(_)" } ], "Ordering": [ { "Name": "measure0", "Direction": "Descending" } ], "AggregateOthers": true, "MaximumRowCount": 20, "EnableResultCaching": true, "ModelId": 123 }') --#RunQuery
Following command gets list of cases for model id 123 and stores results to a datatable MyDataTable in project id 456:
(SELECT 'DataTableName', 'MyDataTable') UNION ALL (SELECT 'ProjectId', '456') UNION ALL (SELECT 'Configuration', '{ "Dimensions": null, "Values": [ { "Name": "dimension0", "Expression": "Name" }, { "Name": "dimension1", "Expression": "StartTime" }, { "Name": "dimension2", "Expression": "EndTime" }, { "Name": "dimension3", "Expression": "Duration?.TotalDays" }, { "Name": "dimension4", "Expression": "LastEvent.TypeName" }, { "Name": "dimension5", "Expression": "Variation.EventTypeCount" } ], "AggregateOthers": false, "MaximumRowCount": 200, "Root": "Cases", "ModelId": 123 }') --#RunQuery
Following command gets list of events and stores results to a datatable MyDataTable in project id 456:
(SELECT 'DataTableName', 'MyDataTable') UNION ALL (SELECT 'ProjectId', '456') UNION ALL (SELECT 'Configuration', '{ "Dimensions": null, "Values": [ { "Name": "Case id", "Expression": "Case.Name" }, { "Name": "Event type name", "Expression": "TypeName" }, { "Name": "Time", "Expression": "Timestamp" }, { "Name": "Difference from previous", "Expression": "(Timestamp-PreviousInCase.Timestamp)?.TotalDays" }, { "Name": "Event index in case", "Expression": "IndexInCase+1" }, { "Name": "Automation", "Expression": "Attribute(\"Automation\")" } ], "Root": "Events", "ModelId": 123 } ') --#RunQuery