How to send Glide Records after quering database from Script Include in JSON format
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 10:47 PM
I have a requirement to Glide a table with specific conditions and result of that query ie records of that table should be returned in JSON Format.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 10:54 PM
You can check out this page (Convert gliderecord to a JSON object), this might answer your question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 10:56 PM
Hi @G Sai Vamshi here is the sample code to get User details
getUser: function()
{
var userInform ={};
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", gs.getUserID());
gr.query();
if (gr.next()){
userInform.name = gr.getValue("name");
userInform.company = gr.getValue("company");
}
var result= JSON.stringify(userInform); // JSON object
return result;
},
Harish
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 10:58 PM
@Harish KM Thanks for your quick response. My requirement is to send the whole user record and user records will be multiple records not a single record. In your code, you are taking single record and only two values. Really appreciate if you throw some insights on my requirement.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎04-02-2024 11:09 PM - edited ‎04-02-2024 11:18 PM
Hi @G Sai Vamshi to push multiple values you would need arrays and then covert to JSON as below
getUser: function()
{
var userData = [];
var gr = new GlideRecord("sys_user");
gr.addQuery("sys_id", gs.getUserID());
gr.query();
while (gr.next()){
var userInform = {};
userInform.name = gr.getValue("name");
userInform.company = gr.getValue("company");
userData.push(userInform);
}
// Convert the array of records to a JSON object
var result= JSON.stringify(userData);
return result;
},
Harish