- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 02:01 AM
Hi All,
I have a requirement Where I want to update the 'short description' of the catalog item to the 'Name of the catalog item' If short description is empty
What is the best way to achieve it
Thanks
Solved! Go to Solution.
- Labels:
-
Scripting and Coding
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 04:06 AM
Hi,
BR will work only for new records
If you want to fix older catalog items with empty short description then you need to run schedule job.
1) check which catalog items are having empty short description
2) then set short description with catalog item name
Sample script below for job
1) test this for 5 records using setLimit(5);
once verified then remove this line setLimit(5);
updateRecords();
function updateRecords(){
var rec = new GlideRecord('sc_cat_item');
rec.addEncodedQuery('short_descriptionISEMPTY');
rec.setLimit(5); // use for testing then remove this line
rec.query();
while(rec.next()){
rec.short_description = rec.name;
rec.update():
}
}
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
08-26-2020 03:07 AM
(function executeRule(current, previous /*null when async*/) {
current.short_description = current.name;
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 03:16 AM
for existing catalog items you need to write one time schedule job
1) check which catalog items are having empty short description
2) then set short description with catalog item name
Sample script below for job
1) test this for 5 records using setLimit(5);
once verified then remove this line setLimit(5);
updateRecords();
function updateRecords(){
var rec = new GlideRecord('sc_cat_item');
rec.addEncodedQuery('short_descriptionISEMPTY');
rec.setLimit(5); // use for testing then remove this line
rec.query();
while(rec.next()){
rec.short_description = rec.name;
rec.update():
}
}
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
08-26-2020 03:53 AM
Hi,
Did you get chance to work on my provided solution?
Thanks,
Dhananjay.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 04:05 AM
Hi Dhananjay,
I tried. Still I am not getting excepted output
On new records it is working fine but it didn't update on existing records
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-26-2020 04:06 AM
Hi,
BR will work only for new records
If you want to fix older catalog items with empty short description then you need to run schedule job.
1) check which catalog items are having empty short description
2) then set short description with catalog item name
Sample script below for job
1) test this for 5 records using setLimit(5);
once verified then remove this line setLimit(5);
updateRecords();
function updateRecords(){
var rec = new GlideRecord('sc_cat_item');
rec.addEncodedQuery('short_descriptionISEMPTY');
rec.setLimit(5); // use for testing then remove this line
rec.query();
while(rec.next()){
rec.short_description = rec.name;
rec.update():
}
}
Regards
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader