- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2016 02:46 AM
It seems if a change is canceled that approvers still have an outstanding task to approve a job which approval is now no longer required.
I thought it would be a buisness rule, but that didnt seem to work.
can someone advise the best way that if a a change is canceled, we then change the state of all approvals to no longer required anc close all tasks related.
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2016 03:56 AM
Hi,
I created a UI Action on the request item table to find and cancel outstanding approvals which is a pretty similar thing to what you're doing.
I used an if(approval.next) cos the existing BRs take into account the other approvals and mark them as not required.... It does highlight how to update the approval record though.... looks like you're referring to client script functions setValue(X,Y) etc etc
approval.state = 'rejected';
approval.comments = "Cancelled by " + user;
approval.update();
Example Script
var user = gs.getUserDisplayName();
var approval = new GlideRecord('sysapproval_approver');
approval.addQuery('sysapproval', current.sys_id);
approval.addQuery('state', 'requested');
approval.query();
if(approval.next()){
approval.state = 'rejected';
approval.comments = "Cancelled by " + user;
approval.update();
gs.addInfoMessage("Request Item: " + current.number + " has been cancelled");
} else {
gs.addInfoMessage("Request Item: " + current.number + " cannot be cancelled as there are no active approvals");
}//end else
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2016 03:56 AM
Hi,
I created a UI Action on the request item table to find and cancel outstanding approvals which is a pretty similar thing to what you're doing.
I used an if(approval.next) cos the existing BRs take into account the other approvals and mark them as not required.... It does highlight how to update the approval record though.... looks like you're referring to client script functions setValue(X,Y) etc etc
approval.state = 'rejected';
approval.comments = "Cancelled by " + user;
approval.update();
Example Script
var user = gs.getUserDisplayName();
var approval = new GlideRecord('sysapproval_approver');
approval.addQuery('sysapproval', current.sys_id);
approval.addQuery('state', 'requested');
approval.query();
if(approval.next()){
approval.state = 'rejected';
approval.comments = "Cancelled by " + user;
approval.update();
gs.addInfoMessage("Request Item: " + current.number + " has been cancelled");
} else {
gs.addInfoMessage("Request Item: " + current.number + " cannot be cancelled as there are no active approvals");
}//end else
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2016 04:53 AM
Hi Ben,
thanks, I did see some results from your script when applied to my business rule, however it did not iterate through each of the outstanding approvals, only changing the first one, however if I changed your if to while, it seemed to do the trick. TYVM
heres my slight modification
var user = gs.getUserDisplayName();
var approval = new GlideRecord('sysapproval_approver');
approval.addQuery('sysapproval', current.sys_id);
approval.addQuery('state', 'requested');
approval.query();
while(approval.next()){
approval.state = 'No Longer Required';
approval.comments = "Cancelled by " + user;
approval.update();
gs.addInfoMessage("Change: " + current.number + " has been cancelled");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2017 09:28 AM
Hi Richard,
New to java script as well and i am facing the same challenge. Can you please let me know the conditions to run in BR and the java scripts that you use that make it work?
Thanks,
Wai S
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-31-2017 09:48 AM
Richard,
Thank you for the script. I made slight modifications on your script as following in BR, use condition when "State" changes to Canceled and it works!
var user = gs.getUserDisplayName();
var approval = new GlideRecord('sysapproval_approver');
approval.addQuery('sysapproval', current.sys_id);
approval.addQuery('state', 'requested');
approval.query();
while(approval.next()){
approval.state = 'No Longer Required';
approval.comments = "Cancelled by " + user;
approval.update();
}
gs.addInfoMessage("Change: " + current.number + " has been cancelled");

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2016 04:18 AM
So you want to say that once change is cancelled you want to make your approval state to cancelled