Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to abort an action in servicenow ?

Smriti Rastogi
Kilo Guru

 

I am using REST Api - async step where I am getting a payload with these details for change request form -

1. Short Description

2. Description

3. Requester

4. Configuration Item

5. Correlation ID

I have made all these mandatory in the body

Now I see if the body is recieved empty the change is still created and flow is completed and flow execution id is sent as a response. 

Ideally , I think it should flow should run into error.

Secondly If the CI which is recieved is not found in ServiceNow or is retired we need to abort the action and send an error message back but I see in this case flow goes into error but still the flow execution id is sent as a response.

Basically how do I send an error response for above cases?

1 ACCEPTED SOLUTION

Mohith Devatte
Tera Sage
Tera Sage

Hello,

Can you try this method

current.setAbortAction(true);

this will abort the current action 

Please accept the solution of it helps you

View solution in original post

9 REPLIES 9

I am using REST Api - async step where I am getting a payload with these details for change request form -

 

1. Short Description

2. Description

3. Requester

4. Configuration Item

5. Correlation ID

I have made all these mandatory in the body

Now I see if the body is recieved empty the change is still created and flow is completed and flow execution id is sent as a response. 

Ideally , I think it should flow should run into error.

Secondly If the CI which is recieved is not found in ServiceNow or is retired we need to abort the action and send an error message back but I see in this case flow goes into error but still the flow execution id is sent as a response.

Basically how do I send an error response for above cases?

Community Alums
Not applicable

Hi @Smriti Rastogi ,

In Servicenow, we have two terms called "Return false" and "current.setAbortAction(true);" which is used to abort a action which gets used but you will have understand the their feature first so, here it is

Return false does just that, - it returns false. It doesn't prevent additional business rules from running.

current.setAbortAction(true); stops the business rule and stops the system from continuing to run additional (higher order) business rules.

Now, how do you use it in a Business Rule ? see below an example :

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 my answer correct & Helpful, if Applicable.

Thanks,
Sandeep

Community Alums
Not applicable

Hi @Smriti Rastogi ,

Glad to see my answer helped you, Kindly mark the answer as Correct & Helpful both such that others can get help.

Thanks,
Sandeep

Rohini Sane
Tera Contributor

Hi,

You can use

current.setAbortAction(true)

this will abort the current action.

Smriti Rastogi
Kilo Guru

We can abort the action using current.SetAbortAction(True) but we do not have an option to send a custom response in flow designer. It always sends the execution id by default.