Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

How to Update the short description and Description on the catalog item

AjKadam
Tera Contributor

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

1 ACCEPTED SOLUTION

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

 

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

View solution in original post

30 REPLIES 30

Hi,

If you want to update existing records then go with Ankurs script.

I tried but it is also not working

AjKadam
Tera Contributor

Thank you, Dhananjay, Ankur

Issues resolved

Actually the same script I tried with 'Script-Background' it worked

I don't know how? Might be a specialty of the 'Script-background'

For more reference find the script,

var vr=new GlideRecord('sc_cat_item');
vr.addActiveQuery();
vr.addEncodedQuery('type!=bundle^sys_class_name!=sc_cat_item_guide^type!=package^sys_class_name!=sc_cat_item_content^short_descriptionISEMPTY');
vr.query();

while(vr.next()){
//vr.setValue('short_description')='hi';
vr.short_description=vr.name;
vr.update();
//gs.addInfoMessage(vr.getRowCount());

}

 

 

Thanks,

Aj

@Aj 

Great!  It looks like you marked your own response as the correct answer, which may be confusing to others that read this later.

If you find my response solved your issue, please mark answer as Correct & ????Helpful to help others with the same response find the answer more quickly

Regards
Ankur

 

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

Hi Ankur,

That was my mistake, thank you for making me correct

 

Regards,

Ajay