- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2017 04:37 PM
When I use the REST Table API to PUT a record in our incident table, I supply it with mandatory fields in the query parameters section, but not all fields are mandatory; there are dozens that are optional. If I supply the API with the mandatory fields and a few optional fields, how does the Table API know when an optional field is present or not present.
Because when I create a scripted REST API to intercept and analyze the PUT request to see if it's a valid add or it needs to be an update instead, I have to define the query parameters. If the parameter is optional I have to test:
if (typeof queryParams.u_services !== "undefined" && queryParams.u_services[0]) {
grIncident.setValue('u_services', queryParams.u_services[0].toLowerCase());
}
Is the code available to developers to see an example of how the Table API PUT handles this?
Background: We are using a third party alarm monitoring tool to create a major incident by a device alarm. When a device alarms, the API needs to check for the device name to see if an incident already exisits for it. If so, the script does an update instead of a put.
Solved! Go to Solution.
- Labels:
-
Best Practices

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2017 10:03 AM
Hi Kimberly,
Thanks for the update. While I don't have direct access to the underlying platform code, I'm fairly certain they check each field before trying to use it. That's just good programming practice. They don't do it field by field, but rather get a list of available fields and run it through a loop. If a field is not defined or doesn't have a value, then they skip over it. Something akin to this:
if (field[i])
grIncident.setValue(field[i], value[i]);

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-13-2017 06:01 PM
Hi Kimberly,
I'm trying to grasp why optional fields matter? I can see wanting to know that all the mandatory fields are there (for this I recommend Data Policies), but let's say the due date is optional, the table API shouldn't really care if it is in the payload anywhere.
Help me understand what I'm missing.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2017 06:30 AM
If I code:
set grIncident.setValue('u_services', queryParams.u_services[0].toLowerCase());
and u_services was not provided, without testing to see if its in the request object, my API raises a type property undefined error. That means I have to test for every possible missing column in my scripted API.
I was just wondering how the Table API does this. When I use it for the Incident table, I do not give it every column in the table and it doesn't give a type error. How does it know which I provided and which I didn't. Does it test for every potential column in order to do the set without error?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-16-2017 10:03 AM
Hi Kimberly,
Thanks for the update. While I don't have direct access to the underlying platform code, I'm fairly certain they check each field before trying to use it. That's just good programming practice. They don't do it field by field, but rather get a list of available fields and run it through a loop. If a field is not defined or doesn't have a value, then they skip over it. Something akin to this:
if (field[i])
grIncident.setValue(field[i], value[i]);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-21-2017 03:47 PM
Kimberly,
We are glad you took advantage of the ServiceNow Community to learn more and to get your questions answered. The Customer Experience Team is working hard to ensure that the Community experience is most optimal for our customers.
If you were not able to receive the answer you hoped for but you do believe that you received clarity in terms of how to proceed, we would greatly appreciate if you could mark the appropriate thread as "Correct Answer". This improves the ServiceNow Community experience.
If you are viewing this from the Community inbox you will not see the correct answer button. If so, please review How to Mark Answers Correct From Inbox View.
Thanks!