- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 07:11 AM
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
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 07:17 AM - edited 05-28-2024 07:19 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 07:54 AM - edited 05-28-2024 08:02 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 07:17 AM - edited 05-28-2024 07:19 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-28-2024 07:54 AM - edited 05-28-2024 08:02 AM
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