- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 02:23 AM - edited 11-14-2023 02:26 AM
Hello All!
I am looking for solution for my below script in Business rule.
I am trying to make an automation of changing Approval State from "Approved" to "Requested" in RITM when Manual Approver in RITM has been created and set as "Requested" in sysapproval approver table.
In WF there is a set value action to make Approval=Approved after RITM creation.
Currently it is not working properly.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("sysapproval", current.request_item);
gr.addQuery("sysapproval", current.sys_id);
gr.addQuery("state", "approved");
gr.query();
if (current.approval == 'approved' && sysapproval_approver == 'requested') {
current.approval == 'requested'; //Approval in RITM
} else
current.approval == 'approved'; /Approval in RITM
})(current, previous);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 02:48 AM
@Lkowalski
Your Business rule was defined as after BR soo here you have to add a logic in your script .
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("sysapproval", current.sys_id);
gr.addQuery("state", "requested");
gr.query();
if (gr.next()) {
current.approval = 'requested';
current.update(); // this is not recommendated in after BR
} else
current.approval = 'approved';
current.update(); // this is not recommendated in after BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 02:27 AM - edited 11-14-2023 02:32 AM
Hi @Lkowalski ,
Change the assignment to single equal sign for assignment.
if (gr.next()) {
current.approval = 'requested';
} else {
current.approval = 'approved';
}
Please mark it as helpful and solution proposed if it serves your purpose.
Thanks,
Anand
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 02:35 AM
Hi Anand,
I changed my script but it still not works.
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("sysapproval", current.request_item);
gr.addQuery("sysapproval", current.sys_id);
gr.addQuery("state", "approved");
gr.query();
if (gr.next()) {
current.approval = 'requested';
} else
current.approval = 'approved';
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 02:48 AM
@Lkowalski
Your Business rule was defined as after BR soo here you have to add a logic in your script .
var gr = new GlideRecord("sysapproval_approver");
gr.addQuery("sysapproval", current.sys_id);
gr.addQuery("state", "requested");
gr.query();
if (gr.next()) {
current.approval = 'requested';
current.update(); // this is not recommendated in after BR
} else
current.approval = 'approved';
current.update(); // this is not recommendated in after BR
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-14-2023 02:58 AM
Now it is working properly :).
I had also needed to remove Approval=Approved from filter condition.
Thank you for support! 🙂