- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 04:08 AM
Hi
I have an Import Set and Transform Map working into Change Request.
I want to introduced a validation step into the Transform to check the Change Request can be updated and if not valid return that fact back to the client.
Looking at Transformation script variables Documentation I have included
error = true;
error_message = "request is already set and doesn't match supplied value";
This stops the import and logs accordingly, but the response to client returns 201 - Created and a normal "result" data block, which I take to be the import record was created.
Is there a way to issue a different HTTP Response code (e.g. 500) and the error message?
Updated: I should indicate that I am currently using REST by POST to https://myinstance/api/now/table/my_app_change_import_rest?sysparm_exclude_reference_link=true
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 05:04 AM
I think if you are using the table API it will be difficult to return an error message in the way that you are describing since the POST message to the import table will always be successful. The transform doesn't occur until after the record is loaded into your import set table so you wouldn't be able to return a response from the transform map through the API.
What you could do is look into the scripted REST APIs. This would allow you to write a script to check the values from the POST message before returning a response.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 05:04 AM
I think if you are using the table API it will be difficult to return an error message in the way that you are describing since the POST message to the import table will always be successful. The transform doesn't occur until after the record is loaded into your import set table so you wouldn't be able to return a response from the transform map through the API.
What you could do is look into the scripted REST APIs. This would allow you to write a script to check the values from the POST message before returning a response.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-14-2019 11:29 AM
Tony hi
Thanks yes, I that explanation makes sense.
The Scripted REST API looks like a possibility, which I may investigate.
For my internal application use, for now, I have added an "already_linked" column to the import set and update source.already_linked = true; in the transform script. This gets returned and I'm able to use that to determine the status of the import from that.
Thanks anyway.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-27-2024 10:57 AM
I realise that I am late to the game, here. But, I feel like we have a similar issue and I read the accepted answer, but I have a follow-up question to the logic presented by @Tony Cattoi
Hi, Tony, you said
The transform doesn't occur until after the record is loaded into your import set table so you wouldn't be able to return a response from the transform map through the API.
In my API results from POSTing to my import set, it does in fact say

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-30-2024 04:40 PM
Wow this is a blast from the past. Good question Brian. With the table api referenced in the original post, I still don’t think you would be able to guarantee you get a response back with the error since we would just be posting to the import set table itself and doesn’t wait for the transform. Maybe if you did a get afterwards it would have that detail but there are other options now.
It looks like in the import set API that you can get a response with this type of detail in many cases so that would be the place to look if you’re posting and wanting to know the result of the transform. https://docs.servicenow.com/bundle/washingtondc-api-reference/page/integrate/inbound-rest/concept/c_...