The CreatorCon Call for Content is officially open! Get started here.

Inbound web service that can both create and update incidents?

peterraeves
Mega Guru

We are creating an Inbound Web Service that can do 3 things. Create, update and close an Incident. What would best practice be here? Should I create 3 services? Should I create a single Service with 3 transform maps? Should I create a single service with a single TM that covers all situations?

I thought about all situations but all of them had bad points to them. So I thought I'd turn to you guys who are much smarter than me.

1. 3 Services & 3 Transform Maps

+: Easier for the external customer, as the name of the service is clear and they will receive only a single result

-: Double work for field maps/values that are the same for all services

2. 1 Service & 3 Transform Maps

+: Single interface, so customer does not need to worry about what to call

+: Only need maps for those fields that are needed for the current service

-: The external customer will receive the results of 3 TMs

-: All TMs need onBefore maps to check whether they should run

-: Double work for field maps/values that are the same for all services

3. 1 Service & 1 Transform Map

+: Everything is centralized

-: Cannot use coalesce field 'number', because it will not be present when creating a new ticket. This will cause the TM to fail.

PS: As a bonus question, where should I put default values. For example, for the contact_type field, I'd like to enter 'Automated Event', which is not the overal default. Where would I put this assignment? Field Map? Transform Script?

1 ACCEPTED SOLUTION

If you check 'Coalesce Empty Field' it'll stop complaining.   That's what we do and it has worked for 2 years now.   If you don't have a coalesce field, how is it going to know what to update?   Even with Table API, you have to pass something to tell it what to update.


View solution in original post

11 REPLIES 11

That's what I did with the number field. The problem is that when your payload does not contain the number field, it will complain. I would have expected it to do an insert at that time, but it complains for the missing coalesce field and skips the record all together. I would prefer to have a service that can be called without the coalesce field and still work, because it would not be very clean to tell the customer to add 'number:' on an insert...


If you check 'Coalesce Empty Field' it'll stop complaining.   That's what we do and it has worked for 2 years now.   If you don't have a coalesce field, how is it going to know what to update?   Even with Table API, you have to pass something to tell it what to update.


In the case there is no coalesce field, it should create a new record.


In the case there is a coalesce field in the payload, it should update the record corresponding the given INC number.


(If the coalesce field contains an invalid INC number, it should reject)


That is what Import Set APIs do:



Import Set API - ServiceNow Wiki



Except maybe the third point.   You may have to script that.  


No they do not



Image 2.png



Even when I enter 'u_number:' in the body, it still complains. It expects some value. I guess I'll just have to use a workaround, which is a Field Map script on sys id. That worked in the past.