Best practice for handling reference field data in scripted rest api

Mahesh122
Tera Contributor

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.

 

4 REPLIES 4

Tushar
Kilo Sage
Kilo Sage

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

 

Ankur Bawiskar
Tera Patron
Tera Patron

@Mahesh122 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader

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.

 

@Mahesh122 

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.

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader