How to Implement Custom Validation in Buy Item POST API Before Request Creation?

AkulaN
Tera Contributor

We are using the Buy Item POST API in ServiceNow to place order requests.

 

We now need to add custom validations (such as checking currency and vendor values) before the request gets created. Currently, validations are happening after the request is created, which is not ideal.

 

What We've Tried

 

Added a Before Business Rule on the request table to perform these validations.

 

When a validation fails, we use current.setAbortAction(true) to block record creation.

 

 

⚠️ Issue Faced

 

The record is correctly not created when validation fails.

 

However, the API still returns a 200 OK response with request details — which is misleading.

 

There is no actual request created in the system.

 

 

Our Requirement

 

We want to perform custom validations before request creation.

 

If the validation fails, the request should not be created, and the API should return a meaningful error response (e.g., HTTP 400/422 with error message).

 

 

🔍 Looking For

 

What is the best way to introduce custom field-level validation logic for the Buy Item POST API?

0 REPLIES 0