How to abort action in scripted rest api

Priyanka145
Tera Contributor

Hi All,

I'm using a scripted rest api to create change from third party tool.

If the user trying to create change from third party is available in ServiceNow users table , then only the change should be created.

If it's not there then change request creation action should be aborted.

 

Please help what is the function that has to be placed to abort the action in scripted rest api. I tried even with abort but still change request is getting created. 

1 ACCEPTED SOLUTION

sushantmalsure
Mega Sage
Mega Sage

@Priyanka145 

Do you mind sharing screenshot of what you have tried in scripted APIs?

 

In scripted rest APIs under the operation there are few options which I will recommend to use when you want to restrict external calls:

1. Requires authentication 

2.Requires ACL authorization : you can here specify ACL and in that can also validate if user is present in servicenow and have sufficient roles

3. you can also do handling in script section before inserting a change request and after validating the user is not present in servicenow then something like, 

eg. return new sn_ws_err.BadRequestError("user not found");

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

View solution in original post

2 REPLIES 2

sushantmalsure
Mega Sage
Mega Sage

@Priyanka145 

Do you mind sharing screenshot of what you have tried in scripted APIs?

 

In scripted rest APIs under the operation there are few options which I will recommend to use when you want to restrict external calls:

1. Requires authentication 

2.Requires ACL authorization : you can here specify ACL and in that can also validate if user is present in servicenow and have sufficient roles

3. you can also do handling in script section before inserting a change request and after validating the user is not present in servicenow then something like, 

eg. return new sn_ws_err.BadRequestError("user not found");

If my answer has helped with your question, please mark my answer as accepted solution and give a thumb up.
Regards,Sushant Malsure

Hi @sushantmalsure 

Thanks, I have kept this and worked well.

return new sn_ws_err.BadRequestError("user not found");