- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 04:06 AM
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.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 04:41 AM
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?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 04:10 AM
Hi,
We dont use getRowCount it is not recommended.
You can simple do like this:
var gr = new GlideRecord('sc_task');
gr.addQuery('request_item', current.sys_id);
gr.query();
var desc;
if (gr.next())
desc = gr.description;
else
desc = current.cat_item;
OR
Use GlideAggregate.
Thanks,
Ashutosh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 04:41 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 04:52 AM
Hi,
sharing link which is for best practice around glideaggregrate and getrowcount
https://mavembry.info/post/gr-and-ga/
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-14-2020 04:12 AM
Hi,
Script looks fine. Seems you are using it as a Business rule script that runs on RITM table after insert/update.
Try replacing
if (count == '1')
with
if (count >=1)