- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 07:34 AM
I need to be able to change the Status of any Change Tasks that are in a pending state to "Open" when a change request progresses to the "Scheduled" state. I have created a After, Update business rule with the following script. The rule is running because I get that message I added, however its still not updating the status of the Change task. What am I missing?
(function executeRule(current, previous /*null when async*/) {
var ct = new GlideRecord("change_task");
ct.addQuery("change_request", current.sys_id);
ct.addQuery("state", "=", -5);
while (ct.next()) {
current.state = "1";
}
})(current, previous);
Solved! Go to Solution.
- Labels:
-
Change Management
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 07:50 AM
Try This -
You don't want to update the state of current but change_task. also update() was missing.
(function executeRule(current, previous /*null when async*/) {
var ct = new GlideRecord("change_task");
ct.addQuery("change_request", current.sys_id);
ct.addQuery("state", "-5");
ct.query();
while (ct.next()) {
ct.state = "1";
ct.update();
}
})(current, previous);
Thanks.
PS: Hit like, Helpful, Correct and Endorse, if it answers your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 07:41 AM
In your while loop, set the state value of the ct record, not current. Your description indicates that you want to update the change task, not 'current' (the change.) You also need to do an update() operation to save the new value to the record.
Example:
while (ct.next()) {
ct.state = 1;
ct.update
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-07-2017 07:50 AM
Try This -
You don't want to update the state of current but change_task. also update() was missing.
(function executeRule(current, previous /*null when async*/) {
var ct = new GlideRecord("change_task");
ct.addQuery("change_request", current.sys_id);
ct.addQuery("state", "-5");
ct.query();
while (ct.next()) {
ct.state = "1";
ct.update();
}
})(current, previous);
Thanks.
PS: Hit like, Helpful, Correct and Endorse, if it answers your question.