Suppose print all incident which priority 1 . How put in array please help me ?

Roshu
Tera Contributor

var priority1Incidents = [];

var gr = new GlideRecord('incident');
gr.addQuery('priority', '1');
gr.query();

while (gr.next()) {
var incident = {
'number': gr.getValue('number'),
'short_description': gr.getValue('short_description'),

priority1Incidents.push(incident);
}
}

gs.info(priority1Incidents);

Please help me in this

2 ACCEPTED SOLUTIONS

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Roshu 

You can try the below code :

The mistake that you have done is that you need to use JSON.Stringify

 

var priority1Incidents = [];

var gr = new GlideRecord('incident');
gr.addQuery('priority', '1');
gr.query();

while (gr.next()) {
    var incident = {
        'number': gr.getValue('number'),
        'short_description': gr.getValue('short_description')
    };

    priority1Incidents.push(incident);
}

gs.info(JSON.stringify(priority1Incidents));

 

 

Thanks and Regards

Sai Venkatesh

 

 

View solution in original post

swathisarang98
Giga Sage
Giga Sage

Hi @Roshu ,

 

In your code you have pushed the jason into variable  priority1Incidents while constructing the Json, so please find the below corrected code, 

 

 

var priority1Incidents = [];
var gr = new GlideRecord('incident');
gr.addQuery('priority', '1');
gr.query();
while (gr.next()) {
    var incident = {
        'number': gr.getValue('number'),
        'short_description': gr.getValue('short_description')
    };
    priority1Incidents.push(incident);
}

var ans = JSON.stringify(priority1Incidents);


for(var i=0;  i<priority1Incidents.length ; i++)
{
	gs.print("Number : "+priority1Incidents[i].number+" Short Desc : "+priority1Incidents[i].short_description);
}

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang

View solution in original post

2 REPLIES 2

SAI VENKATESH
Tera Sage
Tera Sage

Hi @Roshu 

You can try the below code :

The mistake that you have done is that you need to use JSON.Stringify

 

var priority1Incidents = [];

var gr = new GlideRecord('incident');
gr.addQuery('priority', '1');
gr.query();

while (gr.next()) {
    var incident = {
        'number': gr.getValue('number'),
        'short_description': gr.getValue('short_description')
    };

    priority1Incidents.push(incident);
}

gs.info(JSON.stringify(priority1Incidents));

 

 

Thanks and Regards

Sai Venkatesh

 

 

swathisarang98
Giga Sage
Giga Sage

Hi @Roshu ,

 

In your code you have pushed the jason into variable  priority1Incidents while constructing the Json, so please find the below corrected code, 

 

 

var priority1Incidents = [];
var gr = new GlideRecord('incident');
gr.addQuery('priority', '1');
gr.query();
while (gr.next()) {
    var incident = {
        'number': gr.getValue('number'),
        'short_description': gr.getValue('short_description')
    };
    priority1Incidents.push(incident);
}

var ans = JSON.stringify(priority1Incidents);


for(var i=0;  i<priority1Incidents.length ; i++)
{
	gs.print("Number : "+priority1Incidents[i].number+" Short Desc : "+priority1Incidents[i].short_description);
}

 

 

 

Please mark this comment as Correct Answer/Helpful if it helped you.

Regards,

Swathi Sarang