- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 07:25 AM
Hello,
I created a new field (True/False) on Incident form to be updated when, on Task Survey table the "State" field changes to "completed".
the script is as follows:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
inc.addQuery('number', 'current.sys_id');
//inc.addQuery('number','CHG0502941');
gr.addQuery('active', 'false');
inc.query();
while(inc.next())
inc.u_survey_state = 'true';
inc.setWorkflow(false);
inc.autoSysFields(false);
inc.update();
})(current, previous);
However, the above script doesn't work when using "current.sys_id" for number field.
If I hardcode the number value in the script then field value on Incident form changes to "True".
Does anyone have an idea on how to fix this ?
Thanks & Regard,
Neha
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 07:39 AM
Slightly cleaner version:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
if (inc.get(current.task)) {
inc.u_survey_state = true;
inc.setWorkflow(false);
inc.autoSysFields(false);
inc.update();
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 07:36 AM
Hi,
In table Task Survey, you have only the "task" field.
So, you should access the number field value with "current.task.number" and replace it in your query.
Hope this helps,
Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-04-2017 07:39 AM
Hi Neha,
One more update in the script as suggested above.
you can use either of the addQuery
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
inc.addQuery('sys_id', current.task); // use this if you want to query based on sys_id
OR
//inc.addQuery('number', current.task.number); // use this if you want to query based on number
//inc.addQuery('number','CHG0502941');
gr.addQuery('active', 'false');
inc.query();
while(inc.next())
inc.u_survey_state = 'true';
inc.setWorkflow(false);
inc.autoSysFields(false);
inc.update();
})(current, previous);
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎10-05-2017 06:19 AM
Yes, you can use either one of those queries. The first is a touch faster because dot-walking requires data retrieval to get the task record and inspect the number field, whereas current.task is already available in the current record. Why go get more data to do the same thing (unless you MUST have the number for some reason, of course.)
