Sandeep Rajput
Tera Patron

@Asmita7 You can try the following script.

 

var gr = new GlideRecord('incident');
gr.addQuery('category','software');
gr.query();
var jsonArray = [];
while(gr.next()){
var jsonObj = {};
jsonObj["number"] = gr.getValue('number');
jsonArray.push(jsonObj);
}
gs.info(JSON.stringify(jsonArray));

Hope this helps.

View solution in original post

@Asmita7 Is there anything wrong with my answer?

@Sandeep Rajput  ... It's working. Thank you for your time.

PritamG
Mega Guru

 

var gr = new GlideRecord('incident');
gr.addQuery('category', 'software');
gr.query();

var incidents = []; // Array to hold incident numbers
while (gr.next()) {
    incidents.push(gr.number.toString()); // Add incident number to the array
}

var jsonObject = { incidents: incidents }; // Create JSON object
gs.print(JSON.stringify(jsonObject)); // Print JSON object

 

This will output a JSON object with all incident numbers.

 

View solution in original post

Viraj Hudlikar
Tera Sage

Hello @Asmita7 

 

var grINC = new GlideRecord('incident');
grINC .addQuery('category', 'software');
grINC .addActiveQuery();
grINC .query();

var incidents = [];
while (grINC .next()) {
    incidents.push({
        number: grINC .getValue('number'),
        caller: grINC .getDisplayValue('caller_id'),
        assigned_to: grINC .getDisplayValue('assigned_to')
    });
}

var jsonObject = {
    incidents: incidents
};

// Convert the JSON object to a string and beautify it
var beautifiedJson = JSON.stringify(jsonObject, null, 4);
gs.print(beautifiedJson);

 

 

When above code is run in background script output is as below:

VirajHudlikar_0-1737810254593.png

 

If my response has helped you hit helpful button and if your concern is solved do mark my response as correct.

 

Thanks & Regards
Viraj Hudlikar.

 

View solution in original post