- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2016 01:06 AM
Hi everyone,
I would need a business rule that would look if the RITM(sc_req_item) Approval was Rejected and if it did then the Request state must be changed to Closed Rejected and the State of the Request(sc_request) to Closed Cancelled.
I have the below script in an after BR with the condition current.approval.changes() && current.approval == 'rejected' and on the sc_req_item table but it doesn't work.
function onBefore(current, previous) {
var gr = new GlideRecord("sc_request");
gr.addQuery('request_item',current.sys_id);
gr.query();
while (gr.next())
gr.request_state = 'Closed Rejected';
gr.state = 'Closed Cancelled';
gr.update();
}
Thanks,
Bogdan Pirsan
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2016 02:57 AM
Hi Bodgan,
Here is a way to achieve your quiery.
create a new business rules which will run on insert and update. The BR should also run on 'after'
under advanced tab, copy the sript below :
condition : current.stage.changes() && (current.stage=='Request Cancelled')
closeReq();
function closeReq(){
// check to see if any of our peers are currently *not* closed
var gr = new GlideRecord('sc_req_item');
gr.addQuery('request', current.request);
gr.addQuery('state', '7'); // 7 = closed cancelled
gr.query();
if (!gr.next()) {
// no peer ritm is currently open
var sc_request = new GlideRecord('sc_request');
sc_request.addQuery('sys_id', current.request);
sc_request.query();
sc_request.next();
gs.print("SC_REQUEST.STAGE = " + sc_request.stage + " INDEX = " + sc_request.stage.toString().indexOf('closed'));
sc_request.stage = "closed_complete";
sc_request.state = '7';
sc_request.comments.setJournalEntry("Request closed");
sc_request.update();
}}}
I am sorry, but I have one more question : how do you reject your item ? is it from approval ?
if yes, therefore you need this following script in order to cancel your approval in the first place, than cancel your ritm then cancel your request :
Create a BR as following :
table : Approval [sysapproval_approver]
When to run : after
Update : Checked
Filter condition : state changes to cancelled
- var sc_request_item = new GlideRecord('sc_req_item');
- sc_request_item.addQuery('sys_id', current.sysapproval);
- // current is the object of current record. in this case it is sysapproval_approver table record since BR is running on it. there is no field with name 'Request' but //it is the 'sysapproval' which points to the Record for which approval is inserted. I assume it is the RITM record.
- sc_request_item.query();
- while(sc_request_item.next()) {
- sc_request_item.state = "Closed Cancelled";
- // here you need to pass on the VALUE of choice field and not the LABLE, normally OOB values for choice list of state are Integers. So please check this as well
- sc_request_item.stage = "Request Cancelled"; //here you need to pass on the VALUE of choice field and not the LABLE, So please check this as well
- gs.log('Executring BR');
- // always try to log statements in scripts to find whether it is even being fired or not. After successful testing, you can simly comment this out.
- sc_request_item.update();
- }
It will cancel your requested_item and then the business Rules 'Close Parent if Required" will trigger automatically
Test the follwing script and let me know if you need futher info
Kind regards,
ZA
Do not feel shy to mark correct or helpful answer if it helps or is correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2016 03:01 AM
change this
request.state='closed_cancelled';
to
request.state='7';
Kind regards,
ZA
Do not feel shy to mark correct or helpful answer if it helps or is correct
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-10-2016 03:54 AM
Thank you,
I already had the script to cancel the approval and then the RITM, I only needed to cancel the Request as well when it gets rejected.
Best regards,
Bogdan