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

shortRecord();

function shortRecord(){

var vr=new GlideRecord('sc_cat_item');
vr.addEncodedQuery('short_description=NULL');
// vr.addNullQuery('short_description');
vr.setLimit(4);
vr.query();

while(vr.next()){
// vr.short_description="Update";
vr.short_description=vr.name;
vr.update();
}
gs.log('Demo Schecduled job at 4:22 PM');
}

Hi,

try this updated script with logs being added

shortRecord();

function shortRecord(){

var vr=new GlideRecord('sc_cat_item');

vr.addNullQuery('short_description');

vr.addNotNullQuery('name');
vr.setLimit(4);
vr.query();

gs.info('Row Count is:' + vr.getRowCount());

while(vr.next()){
vr.short_description = vr.name;

gs.info('Record update');
vr.update();
}
gs.Info('Demo Schecduled job at 4:22 PM');
}

Regards
Ankur

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

Still same

4 Logs 

Row Count - 4

@Aj 

So the row count is 4.

Did you check whether it updated the short description with the name as well.

Regard
Ankur

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

Hi,

Are you running BR on insert update OR only on insert?