How to send Glide Records after quering database from Script Include in JSON format

G Sai Vamshi
Mega Guru

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.

7 REPLIES 7

Really appreciate that..I was able to crack the code till the same point. but where i am facing the difficulty is I need to push whole user record instead of two fields in an object and I need to get those user record values in the client side. 

Hi @G Sai Vamshi what do you mean whole record? you want all the fields? then you need to push all the fields like below

userInform.field1= gr.getValue("field1");
userInform.field2= gr.getValue("field2");

userInform.field3= gr.getValue("field3");

so on

 

and finaly push all records

userData.push(userInform);

and in client script you need to parse the answer like below

var result = JSON.parse(answer); // using glideajax

Please provide your use case in detail to assist further.

Regards
Harish

Hi @G Sai Vamshi another way to get all fields is like this but consider performance issue here, do you really want to send all fields?

script:

var gr = new GlideRecord('sys_user');
gr.addActiveQuery();// Some appropriate filter here for better performance
gr.query();
var results = [];
while (gr.next()) {
var fields = gr.getFields();
result = {};
for (i = 0; i < fields.size(); i++) {
field = fields.get(i).getName();
result[field] = gr.getValue(field);

}
results.push(result);
}
var result= JSON.stringify(results);
gs.info(result);

 

Regards
Harish