How can i print 10 problem records data with script.

Neerudus
Tera Contributor
 
2 ACCEPTED SOLUTIONS

RathanK
Kilo Guru

Hello @Neerudus 

 

You can use Background script to print 10 problem records data.

Use the below script and run it in background script, you can add the conditions you want if needed.

 

var gr = new GlideRecord('problem');
gr.query();
var count = 0;

while (gr.next() && count < 10) {
    gs.print('Number: ' + gr.getValue('number'));
    gs.print('Problem Statement: ' + gr.getValue('short_description'));
    count++;
}
 
Regards,
Rathan K
If you found my response helpful, please give it a thumbs-up and designate it as solution accepted to support fellow developers and admins.


Regards,
Rathan K

View solution in original post

Juhi Poddar
Kilo Patron

Hello @Neerudus 

Please refer the script below:

var gr = new GlideRecord('problem');
gr.orderByDesc('sys_created_on');
gr.setLimit(10); 
gr.query(); 

var count = 0;
while (gr.next()) {
    count++;
    gs.print("problem #" + count + ":\nNumber:" + gr.number + "\nCreated On: " + gr.sys_created_on.getDisplayValue() + "\n");
}

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You

Juhi Poddar

View solution in original post

4 REPLIES 4

Viraj Hudlikar
Tera Sage

Hello @Neerudus 

 

var problemGr = new GlideRecord('problem');
problemGr.addQuery('active', true); // Optional: filter for active problems
problemGr.setLimit(10); // Limit to 10 records
problemGr.query();

gs.print('--- Displaying 10 Problem Records ---');

while (problemGr.next()) {
    gs.print('Problem Number: ' + problemGr.number +
              ', Short Description: ' + problemGr.short_description +
              ', State: ' + problemGr.state.getDisplayValue() + // Get display value for choice fields
              ', Assigned To: ' + problemGr.assigned_to.name // Get name for reference fields
             );
    // You can add more fields as needed, e.g.:
    // gs.print('Description: ' + problemGr.description);
    // gs.print('Category: ' + problemGr.category);
}

gs.print('--- End of Problem Records ---');

 

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.

@Neerudus 
Any issue with my solution?

RathanK
Kilo Guru

Hello @Neerudus 

 

You can use Background script to print 10 problem records data.

Use the below script and run it in background script, you can add the conditions you want if needed.

 

var gr = new GlideRecord('problem');
gr.query();
var count = 0;

while (gr.next() && count < 10) {
    gs.print('Number: ' + gr.getValue('number'));
    gs.print('Problem Statement: ' + gr.getValue('short_description'));
    count++;
}
 
Regards,
Rathan K
If you found my response helpful, please give it a thumbs-up and designate it as solution accepted to support fellow developers and admins.


Regards,
Rathan K

Juhi Poddar
Kilo Patron

Hello @Neerudus 

Please refer the script below:

var gr = new GlideRecord('problem');
gr.orderByDesc('sys_created_on');
gr.setLimit(10); 
gr.query(); 

var count = 0;
while (gr.next()) {
    count++;
    gs.print("problem #" + count + ":\nNumber:" + gr.number + "\nCreated On: " + gr.sys_created_on.getDisplayValue() + "\n");
}

Hope this helps!

 

"If you found my answer helpful, please like and mark it as an "accepted solution". It helps future readers to locate the solution easily and supports the community!"

 

Thank You

Juhi Poddar