REST API: updating an incident should never create a new incident

jensst
Kilo Explorer

Hello,

I understand that it is possible to use the Service Now Rest API to post data to the import set table:Import Set API - ServiceNow Wiki

I can see that there are two supported methods:

1) POST /api/now/import/(staging TableName) Inserts a new record into the import set staging table.

2) GET /api/now/import/(TableName)/(sys_id) Retrieves a specific import set record and associated target records created as part of the transformation.

Now I would like to update a specific incident. I know it is possible to use the post method which will either insert a new incident or update an existing incident if the defined coalesce field in the transform map matches an existing record.

This is not exaclty what I try to achieve; I would like make sure only updates are performed. If there is no existing incident no new incident should be created.

Does anyone have an idea how to achieve this?

thanks and regards,

Jens

1 ACCEPTED SOLUTION

Christopher_Mal
ServiceNow Employee
ServiceNow Employee

Not sure if someone else already mentioned this, but I will add that you can use your import set table and have a simple transform script that ignores the action if the action is insert.  



You would include the following code in your transform script: (referenced in the wiki here: http://wiki.servicenow.com/?title=Transform_Map_Scripts#gsc.tab=0)



if (action == "insert")


  ignore = true;


View solution in original post

10 REPLIES 10

epam
Kilo Guru

Hi Jens,



In ServiceNow, there is java processor called RESTAPIProcessor that is not accessible for developers. Therefore you will not be able to modify POST method in order to cut off ability of creating new records.



However, you may try set up Transform map and Transform script of an import set table the way you want it to behave.




Following url also might be helpful:



Re: Through REST API, can we create a staging table?


jensst
Kilo Explorer

Thanks for the reply. we have a transform map and transform scripts but how can this help resolving the issue of not creating new incidents?


Jace Benson
Mega Sage

Another option would be creating your own processor instead of using SN's.   However this would be more maintenance as new features would have to be added and such but you'd have absolute control on how it would work.


ChrisBurks
Mega Sage

Thinking about this I would try and walk through again what is actually known, needed, and what and how it would be achieved.


1) POST and GET are the only supported methods.


2) Updates are the only needed function to be achieved.


3) Coalescing a field can prevent duplication. Possible fields to coalesce on: number, correlation id, or custom field


4) In order to update an existing record that record needs to be identified. Possibly the best identifier would be the field chosen to coalesce on.


5) a)When needing to update use GET to search for an existing record with the identifier. If the identifier (coalescing field/data) is not found don't send request.


      b) If found, send request ensuring that the coalescing data is sent with it. This should create an update and prevent a new record creation.  



If everything is set correctly only updates should occur.


Just sharing some thoughts. May be they can help.