- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2020 02:40 AM
Hi SD,
I need help in Business rule , My requirement is whenever Approver click on Approve button before approving the request current action date and Due date of RITM form should be check and condition is if current updating date is greater than Due date) then its abort the approving action .
I have created business rule its showing error but request getting approve..
Business rule:before-Update
when to run: state is requested
(function executeRule(current, previous /*null when async*/) {
// Add your code here
var now = new GlideDateTime();// current date time
gs.addInfoMessage('current updated date..'+now);
var duedate= new GlideDateTime(current.sysapproval.due_date);
gs.addInfoMessage('.due date is ....'+duedate);
if(now.getDate() > duedate.getDate()){
current.setAbortAction(true);
//gs.addErrorMessage('please select the future dates');
}
})(current, previous);
please help me in the script .
Solved! Go to Solution.
- Labels:
-
Service Catalog
- 37,143 Views
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 06:30 AM
Thanks Ashutosh,
I have changed in Approval Ui Action and its working now hope this will help to other(i am applying this script only if Group SLA is 6 this field is available on RITM form )
UI Action -Approval, table- sysapproval_approver(OOB button)
script
if(current.sysapproval.u_group_sla=='6')
{
var now = new GlideDateTime();// current date time
gs.addInfoMessage('current updated date..'+now);
var duedate= new GlideDateTime(current.sysapproval.due_date);
gs.addInfoMessage('.due date is ....'+duedate);
if(now.getDate() > duedate.getDate()){
gs.addErrorMessage('please select the future dates');
current.setAbortAction(true);
}
else
{
current.state='approved';
current.update();
new ApprovalUserFeedback().approved(current);
}
}
else{
current.state='approved';
current.update();
new ApprovalUserFeedback().approved(current);
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 12:27 AM
Hope you are doing good.
Did you get a chance to check on both the approaches I suggested.
if you think there is any response that helps you please mark that helpful or accepted so that this thread can be closed.
Regards
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
07-08-2020 03:13 AM
HI,
You can put this code in UI Action or do check in UI Action script itself and then show the error from there.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 06:30 AM
Thanks Ashutosh,
I have changed in Approval Ui Action and its working now hope this will help to other(i am applying this script only if Group SLA is 6 this field is available on RITM form )
UI Action -Approval, table- sysapproval_approver(OOB button)
script
if(current.sysapproval.u_group_sla=='6')
{
var now = new GlideDateTime();// current date time
gs.addInfoMessage('current updated date..'+now);
var duedate= new GlideDateTime(current.sysapproval.due_date);
gs.addInfoMessage('.due date is ....'+duedate);
if(now.getDate() > duedate.getDate()){
gs.addErrorMessage('please select the future dates');
current.setAbortAction(true);
}
else
{
current.state='approved';
current.update();
new ApprovalUserFeedback().approved(current);
}
}
else{
current.state='approved';
current.update();
new ApprovalUserFeedback().approved(current);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2020 06:40 AM
Nice.
this was from the start.
I am glad it helped.
Thanks,
Ashutosh