getrowcount for GlideRecord

ceraulo
Mega Guru

Hello!

The objective of my script below is to get the Description field of the SCTASK from the RITM table. If there are more than one SCTASK for the RITM, it would get the value of the ITEM field.

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.query();

var count = gr.getRowCount();
var desc;

if (count == '1')
desc = gr.description;
else
desc = current.cat_item;

Please help!

Thank you.

1 ACCEPTED SOLUTION

I was able to make this work with this script:

 

var count = 0;
var desc;

var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.query();

while (gr.next()) {
count = count + 1;
}

if (count == 1) {
desc = gr.description;
}
else {
desc = current.cat_item.getDisplayValue();
}

 

May I also know why getRowCount is not recommended?

View solution in original post

5 REPLIES 5

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

please give an overview on where this script is written on which BR?

What exactly is required?

Regards
Ankur

Regards,
Ankur
✨ Certified Technical Architect  ||  ✨ 9x ServiceNow MVP  ||  ✨ ServiceNow Community Leader