I want to Update short description on RITM from Values in Array.

pandeyved
Tera Contributor

Hi all,

I want to update the Short description field with values received from user in the form of array.

for eg:

user has passed in JSON:

{"short_description":"current.cat_item.name,-,current.variables.variable_name.display_value"}

 

It should update short description like this: Catalog Item Name - variable display value

So I converted it in Array:

Let's say like this:

var val = "";
var arr = ["g.cat_item.name","-","g.variables.variable_name.display_value"];
var g= new GlideRecord("sc_req_item");
g.addQuery('sys_id','7077e4b01bdcf918aa6ffd949b4bcba7');
g.query();
if(g.next())
{
for(var i=0;i<arr.length;i++)
{
val = val+ arr[i];
}
g.short_description = val;
g.update();
}

But it's not printing.

 

Please guide.

 

3 REPLIES 3

Anil Lande
Kilo Patron

Hi,

Where exactly you are using this script?

var val = "";
gs.info('ABCD - Running my script');
var arr = ["g.cat_item.name","-","g.variables.variable_name.display_value"];
var g= new GlideRecord("sc_req_item");
g.addQuery('sys_id','7077e4b01bdcf918aa6ffd949b4bcba7');
g.query();
if(g.next())
{
gs.info('ABCD - my script got RITM '+g.number);
for(var i=0;i<arr.length;i++)
{
gs.info('ABCD -my script inside for loop adding val = '+arr[i]);
val = val+ arr[i];
}
gs.info('ABCD - my script final short Desc = '+val);
g.short_description = val;
g.update();
}

 

Try above and see what all logs you are getting.

 

Please appreciate the efforts of community contributors by marking appropriate response as correct answer and helpful, this may help other community users to follow correct solution in future.
Thanks
Anil Lande

Hi @Anil Lande 

Thanks for your help.

Let's say I have made a request with "abcd" catalog. This "abcd" catalog has "xyz" variable as question whose answer I have given as "test".

When I am running this script in Background Script, 

It is updating the Short Description of RITM as: 

g.cat_item.name-g.variables.variable_name.display_value

 

But my expectation is this:

abcd - test(according to above defined scenario).
Pls assist thanks.

Kalyani Jangam1
Mega Sage
Mega Sage

Hi @pandeyved 

Please use arr variable in below of (g.next()) because in arr you declared object.variable name. Your code like below

 

var val = "";

var g= new GlideRecord("sc_req_item");
g.addQuery('sys_id','20487c3847103110a806afb8036d4374'); // sys_id of your catalog
g.query();
if(g.next())
{
var arr = ["g.cat_item.name","-","g.variables.variable_name.display_value"]; // catalog item name
gs.info(arr);// Check correct value came from arr or not
for(var i=0;i<arr.length;i++)
{
val = val+ arr[i];
gs.info("val========"+val); // Please check what value came
}
g.short_description = val;
g.update();
}

 

Please check and Mark Helpful or correct if it really helps you.