- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-05-2025 11:49 PM
We integrated external system data to ServiceNow and noticed number of records fields having 'null' value and that needs to exclude from payload
Response body [{"name":"system","list":"worker","id":"null"}]
whenever response body having id=null then it should exclude , how to achieve this?
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 02:18 AM
you can parse the JSON response and skip the null records if id key has null value in it
Something like this, I considered 2 objects came and 1 has id=null and it gave me only 1
You can use that as reference point and continue your further logic
var response = [
{"name":"system","list":"worker","id":"null"},
{"name":"system2","list":"worker2","id":"123"}
];
// Filter out objects where id is "null" (as a string) or null (actual null)
var filtered = response.filter(function(item) {
return item.id !== "null" && item.id !== null;
});
// Now 'filtered' will only contain objects with valid 'id' values
gs.info(JSON.stringify(filtered));
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 02:08 AM
Hi,
Try to add filter to the endpoint/url
https://xxxx.service-now.com?$format=json&$filter=id ne null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 02:13 AM - edited 06-06-2025 02:16 AM
We are pulling record from outside application and endpoint is not ServiceNow
S0 , are you saying need to add external application url to modify with filter condition?
any method to do from ServiceNow side?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 02:19 AM
How are you pulling records?
If you have external application URL or endpoint just add filter to it
https://xxxx.external.url.com?$format=json&$filter=id ne null
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-06-2025 02:18 AM
you can parse the JSON response and skip the null records if id key has null value in it
Something like this, I considered 2 objects came and 1 has id=null and it gave me only 1
You can use that as reference point and continue your further logic
var response = [
{"name":"system","list":"worker","id":"null"},
{"name":"system2","list":"worker2","id":"123"}
];
// Filter out objects where id is "null" (as a string) or null (actual null)
var filtered = response.filter(function(item) {
return item.id !== "null" && item.id !== null;
});
// Now 'filtered' will only contain objects with valid 'id' values
gs.info(JSON.stringify(filtered));
If my response helped please mark it correct and close the thread so that it benefits future readers.
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader