How to abort the action in Business rule

Santoshi5
Giga Guru

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 .

 

 

 

1 ACCEPTED SOLUTION

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);
}

 

 

 

 

View solution in original post

13 REPLIES 13

Ankit Jain5
Giga Expert

No need to enter the script here.
Just fix the conditions as per your need of date
and in second tab there is option to abort action, just check that box.

Thanks Ankit for the reposne , 

Could you please help with the conditions, please confirm where to write my error message while aborting action?

 

 

Hi Santoshi,

this should help you

Few corrections

1) BR should be running before update State is Approved

2) you should give message first and then abort

Business rule:before-Update

when to run: state is approved

(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 > duedate){

gs.addErrorMessage('please select the future dates');
current.setAbortAction(true);

}

})(current, previous);

Regards
Ankur

 

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Hi Santoshi,

If you don't require script then try this

BR: Before update

Condition: Approval.Number [STARTSWITH] RITM && State == 'Approved' && Approval.Due Date before Today

In Actions tab

1) the Abort action as true

2) Add message as true

3) Your message there

find_real_file.png

find_real_file.png

Regards
Ankur

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader