- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 04:33 PM
Hi All,
We have a requirement to build a JSON object of the current record and send it to external system. One of the options that was explored is to call the table API of the same instance and build the payload. Can anyone suggest if there is any other option to retrieve all the fields of a record. If not, could you please let me know if there are any drawbacks of calling table API within same instance.
Thanks in advance.
Regards
Dinesh
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 08:22 PM
can you try this script to build JSON.
I think you don't need to sent all fields to external tool only few required fields need to send. but if you need to send all fields then you can use below script
var incGr = new GlideRecord('incident');
incGr.get('c24f07da1b3809908e81fd115b4bcb9a');
var body={};
var fields = incGr.getFields();
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var name = field.getName(); // Name of the field
var label = field.getLabel(); // Label of the field
var value = field.getDisplayValue(); // Value of the field
body[label]=value;
};
gs.print(JSON.stringify(body,null,4))
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 07:12 PM
Hello Dinesh
As for the drawbacks of calling the table API within the same instance, there could be potential performance issues if the table API is called frequently and in large quantities. Additionally, if the table API is called excessively, it could lead to issues with database locking and negatively impact other system users. It is recommended to use the REST API with caution and to monitor performance to ensure that it does not negatively impact the system.
Reg
Hemant Kumar Ch
Developer-Ciena
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 07:30 PM
Apart from Table API is there any other efficient alternative to get the record data and build a payload?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 08:27 PM
Hi @dineshchoudhary ,
As per your requirement the Table API is the best one but it would lead to performance issues if you do it on every record creation in the table.
My recommendation would be instead of calling Table API on every record creation/updation. Trigger the REST API every 6 hours(as per your wish) to fetch the data created/updated in the past 6 hours and transfer the data to the external system.
This method would reduce the number of Table API calls only 4 per day and you won't need to write customized scripts to achieve this.
If you want to customize, you can write a Scripted REST API to do the same.
Please mark correct if my response has solved your query.
Cheers,
Mohammed Basheer Ahmed.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-23-2023 08:22 PM
can you try this script to build JSON.
I think you don't need to sent all fields to external tool only few required fields need to send. but if you need to send all fields then you can use below script
var incGr = new GlideRecord('incident');
incGr.get('c24f07da1b3809908e81fd115b4bcb9a');
var body={};
var fields = incGr.getFields();
for (var i = 0; i < fields.size(); i++) {
var field = fields.get(i);
var name = field.getName(); // Name of the field
var label = field.getLabel(); // Label of the field
var value = field.getDisplayValue(); // Value of the field
body[label]=value;
};
gs.print(JSON.stringify(body,null,4))