Best practice for handling reference field data in scripted rest api
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2025 07:40 AM
Dear all,
What is the best practice to share all table data along with reference field data through a Scripted REST API? For example, if a table has 10 reference fields, I need to include data from all 10 referenced tables while sending it to a third-party tool.
Should we retrieve all reference field data within a single Scripted REST API, or is it better to create separate table-specific APIs for each referenced table?
Any help would be appreciated.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2025 08:01 AM
Hi @Mahesh122
Retrieve All Reference Field Data in a Single API Call (Best for Smaller Datasets) while create Separate APIs for Each Referenced Table (Best for Large Datasets)
Consider pagination if you are dealing with large datasets and optimize the queries using GlideAggregate and indexed queries for performance.
- Always validate reference field data before processing and handle null values appropriately
- Please Implement proper error handling
Thanks,
Tushar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2025 08:27 AM
1 Scripted REST API and within the script fetch the data and send all at once.
Why to use separate API endpoint?
Consider that 3rd party wants to see incident related data and they consume Scripted REST API, you can send Assigned to, CI, Group, Service Offering etc data which are reference type in single response.
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
‎03-11-2025 08:35 AM
Hi Ankur ,
Thank you for quick response.
But what i mean is , lets say if we have assignment group reference field on incident form, they want assignment group data like name manager description from group table , for CI along with CI name they want support group , short description , etc. ...like wise for ref fields they need data.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎03-11-2025 08:34 PM
yes simply query the table being referred and get the data and send as single response.
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