- 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:29 AM
Hi Neha,
you have an error in your script
current.sys_id should not be within quotes
Also check you are comparing the sys_id with number column, use proper column there
I checked in my demo instance. There is a field 'task' which refers Incident table etc so I have updated the code as well
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
inc.addQuery('task', current.sys_id); // use this now and check
//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-04-2017 07:37 AM
FWIW, there's no 'task' field on the incident (or task) table.
This is likley more what you need:
(function executeRule(current, previous /*null when async*/) {
var inc = new GlideRecord('incident');
inc.addQuery('sys_Id', current.task); // use this now and check
inc.addQuery('active', false);
inc.query();
while(inc.next())
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: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-05-2017 03:07 AM
Thank You Chuck,
This works.
Regards,
Neha
