diff --git a/Core ServiceNow APIs/GlideRecord/getEncodedQuery/Create Incident Task With Same Group b/Core ServiceNow APIs/GlideRecord/getEncodedQuery/Create Incident Task With Same Group new file mode 100644 index 0000000000..fd1e9f73d4 --- /dev/null +++ b/Core ServiceNow APIs/GlideRecord/getEncodedQuery/Create Incident Task With Same Group @@ -0,0 +1,13 @@ +var incRec = new GlideRecord('incident'); +incRec.addEncodedQuery('assignment_group=287ee6fea9fe198100ada7950d0b1b73^active=true'); // sys_id of assignment group is used. Return active incidents assigned to group. +incRec.query(); +var eQry = incRec.getEncodedQuery(); // return the encoded query, applied above. + +while(incRec.next()){ + var iTask = new GlideRecord('incident_task'); + iTask.initialize(); + iTask.applyEncodedQuery(eQry); // applies the encoded query fields to new incident task record. + iTask.setValue('incident', incRec.getUniqueValue()); + iTask.insert(); +} + diff --git a/Core ServiceNow APIs/GlideRecord/getEncodedQuery/README.md b/Core ServiceNow APIs/GlideRecord/getEncodedQuery/README.md index 0d8b0e17e9..6e72fa12c7 100644 --- a/Core ServiceNow APIs/GlideRecord/getEncodedQuery/README.md +++ b/Core ServiceNow APIs/GlideRecord/getEncodedQuery/README.md @@ -1,3 +1,12 @@ +/* This script will glide all active incidents assigned to a particular group and create incident task with same group. +This was a client requirement, where for a particular group they wanted a task generated to log some internal extra work they were doing, during some of their internal transition. +This was done through a scheduled job (daily) for the required period and then the scheduled job was deactivated. + +This can be further used in scenarios where organizations want to log some extra work in a different record. + +sys_id in script is of the group being used. +*/ + 1.In any GlideRecord query retrieve query using getEncodedQuery() 2.Apply this encoded query to create/update records (you can apply this query to other tables if query is appropriate).