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.

Terminate Data Resource with failure message

Sanjay Kumar3
Mega Sage
Mega Sage

Hi Community Members,

I’m working with a Data Resource of type Transform, where mutating is set to true (so it doesn’t return a value). I have a use case where I need to run a script via this Data Resource to validate certain fields and update records accordingly.

Here’s the scenario:

  • If all required fields are filled in, the record should be updated.
  • If any required field is missing, I want to terminate the Data Resource execution and trigger a failure event, which I can then use to display an appropriate error message.

Is there a recommended way to gracefully terminate the Data Resource in such cases and map it to a failure event?

Thanks in advance!

Regards,
Sanjay Kumar

1 ACCEPTED SOLUTION

Hi Shashank,
The above didn't work.
But we found a solution.

return new Error("Validation failed");
//This would terminate the script broker execution and we can configure the failure event for the data resource


Thanks,
Sanjay

View solution in original post

2 REPLIES 2

Shashank_Jain
Kilo Sage

@Sanjay Kumar3 ,

 

1. Use actionResponse.setError("message") → it stops execution and shows the error in Test Load 

(Inside the Server Script function signature)

 

 

If this works, please mark it as helpful/accepted — it keeps me motivated and helps others find solutions.
Shashank Jain

Hi Shashank,
The above didn't work.
But we found a solution.

return new Error("Validation failed");
//This would terminate the script broker execution and we can configure the failure event for the data resource


Thanks,
Sanjay