otedikova
otedikova

Reputation: 21

Servicenow REST-API returns 200 Ok in case of business logic errors

I'm using servicenow rest-api to update sys_user table entry. I have a column constraint on Home Phone field, it is mandatory. But when send a request for update which makes Home Phone empty, servicenow accepts this request and updates a user and returns 200 OK response. I also tried to use Business rules to add this validation and throw an exception in script, but service now ignores it.

I want service now to return an error in response in such cases. Is it possible?

Upvotes: 0

Views: 938

Answers (2)

user25059906
user25059906

Reputation: 1

Make the field coalesce in field mapping . And also set it choice action of the field to create

Upvotes: 0

BryanJ
BryanJ

Reputation: 213

I would suggest using an import set and the import API instead of the table API. By using an import set you can easily control imports via several methods:

  • You could enforce mandatory fields by setting a field mandatory on a table via the dictionary and if the enforce mandatory fields box is checked on the import set it will reject (but this might not stop null entries)
  • If nulls are slipping in you can use a transform map to make certain fields required (required for the import set but they may not be mandatory on the target table) and then you can apply a script to a field to manipulate it or reject based on its content using functions like JSUtil.notNil(source.home_phone).
    • You can also apply onBefore Transform scripts. Ex: This will cause the API to respond with a custom error message // if home phone is not null, undefined, Nan, empty string (""), 0 or false this evalutes to true.
      if (source.home_phone) { error = false; } else{ error_message = "Home Phone is a required field"; error = true;" }

Upvotes: 0

Related Questions