I want to Update short description on RITM from Values in Array.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 11:08 PM
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.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-24-2023 11:38 PM
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.
Thanks
Anil Lande
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 12:33 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-25-2023 12:08 AM - edited 07-25-2023 12:10 AM
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.