how to set description dynamically?

Priti18
Tera Expert

if there are multiple catalog items with same wf  but every time description field is getting changed so in run script activity how can we set it dynamically

1 ACCEPTED SOLUTION

Hi,

As I mentioned please don't use current.update()

Now are you using correct sys_id and correct variable name there i.e. variablename1

Did you check that variable value is empty or not

Regards
Ankur

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

View solution in original post

12 REPLIES 12

Prasad Dhumal
Mega Sage
Mega Sage

Way 1 :

var text = 'Setting Description';
var gr = new GlideRecord('sc_request');
if(gr.get(current.change.sys_id)){     // Here change should be your reference field on request
    gr.description = text;
    gr.update();
}

Way 2 :

var gr = new GlideRecord('sc_request');
gr.addQuery(current.request);
gr.query();
if (gr.next())
{
gr.short_description = current.cat_item.short_description;
gr.description = current.cat_item.description;
gr.update();
}

 

 

Aman Singh_
Kilo Sage

Hi,

 

You can verify the catalog item and set the description as

Assuming your wf is set on sc_req_item table.

if(current.cat_item=='sys_id of catalog item')
{
current.description='ABC';
current.update();
}
if(current.cat_item=='sys_id of 2 catalog item')
{
current.description='ABC';
current.update();
}

Or

if you want to set the description from the description of catalog item.

current.description=current.cat_item.description;
current.update();

Thanks,

Aman

Ankur Bawiskar
Tera Patron
Tera Patron

Hi,

If same workflow is attached to multiple catalog items then in run script you can determine what is the catalog item name and based on that set the description

var itemName = current.cat_item.name;

if(itemName == 'Raise Hardware Request'){
	current.description = 'Your Description';
}

if(itemName == 'Raise Software Request'){
	current.description = 'Your Another Description';
}

Regards
Ankur

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

Priti18
Tera Expert

this is the code which am using in run script

answer = desc();

function desc() {


if (current.cat_item == 'sys id of catalog item') { 

current.description = current.variables.variablename1.toString();


}
else if (current.cat_item == 'another sys id'){

current.description = current.variables.variablename2.toString();


}

current.update();
}