- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2014 02:28 PM
Context: In a catalog task, I have a UI action to create a change request. When creating the change request, I need to copy the variables and values from the variables attached to the task's parental requested item.
While I know how to copy any specific variable from the task's parent to the change request's description field, I need a general method to copy whatever variables are present in the task's parental requested item to the change request's description field. I suspect that it will involve enumerating over the current.parent.variables item, but for the life of me, I haven't even got to first base yet!
Solved! Go to Solution.
- Labels:
-
Service Mapping
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2014 12:42 PM
Thank you everyone for the ideas. They were insightfull and they helped guide me to the solution that I'm using.
To reiterate the context: I have a UI Action " Create Change" in the catalog task record so that people can open a change record from a request. The request often comes with catalog variables and I need to copy them to the change request's description. Here's a snippet of code that works: The part that is missing is the instantiation of the change object with Glide Record to create the new change request, and the insertion afterward.
var lov = "\nList of Variables from Requested Item"; // lov = list of variables
for (var prop in current.parent.variables )
{
lov = lov + "\n" + prop + " = " + current.parent.variables[prop].getDisplayValue();
}
change.description = change.description + lov;
--------------- new edits below this line ------------------------------------
The solution above copies the variables in a somewhat random way. I decided to list them in a sorted order.
That way, with "intelligent variable names", like items could be sorted together.
The following code will copy the variables to the change.description field as the above examble:
I'm embarrassed to say how long it took me to figure this out and I invite you to show me an easier way to do this.
Again, this is missing is the instantiation of the change object with Glide Record to create the new change request, and the insertion afterward.
The code:
var lov = "\n\n===== List of Variables from Requested Item (" + current.parent.number + ") =====";
var index = 0;
var array = [];
for (var prop in current.parent.variables )
{
array[index] = prop;
index++;
}
var sorted = array.sort();
for ( x = 0; x<sorted.length; x++)
{
var key = sorted[x];
var value = current.parent.variables[key].getDisplayValue();
var line = "\n-> variable " + key + " = " + value;
if ( /\n/m.test(value) )
{
line = "\n-> variable " + key + " (multi-line) follows: --\n" + value + "\n<--- end of multi line variable " + key + " ---";
}
lov = lov + line;
}
change.description = "From " + current.parent.number + " -> " + current.number + ": " + current.short_description + "\n" + current.description + lov;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2014 07:51 PM
You may want to have a look at the solution I provided in other thread.
Variable names in Catalog Client Script
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-02-2014 11:19 PM
Hi,
I was also having similar requirement from one of my client. To achieve this, I have copied variable pool from RITM to Change Request on Change creation from RITM. And added variable editor to change form. Please refer below script for your reference:
Condition: current.parent.sys_class_name == 'sc_req_item'
Before Insert
Script:
var ritmv = new GlideRecord('sc_item_option_mtom');
ritmv.addQuery('request_item',current.parent);
ritmv.query();
while(ritmv.next()){
var ritmO = new GlideRecord('sc_item_option');
ritmO.addQuery('sys_id',ritmv.sc_item_option);
ritmO.query();
while(ritmO.next())
{
var childV = new GlideRecord('question_answer');
childV.table_name = current.sys_class_name;
childV.value = ritmO.value;
childV.order = ritmO.order;
childV.question = ritmO.item_option_new;
childV.table_sys_id = current.sys_id;
childV.insert();
}
}
Please mark answer as correct/helpful, if it was helpful
Regards,
Solutioner
Enhance Knowledge NOW@ www.solutioningnow.com
http://www.solutioningnow.com/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
08-15-2014 11:20 AM
Perfect Solutioner Now...
I have been needing this to display variables on tasks generated from an item workflow that are not catalog tasks.
It seems that ServiceNow could create this functionality fairly easily that mimicked the catalog task variable functionality for other tasks generated in a workflow.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-19-2014 12:42 PM
Thank you everyone for the ideas. They were insightfull and they helped guide me to the solution that I'm using.
To reiterate the context: I have a UI Action " Create Change" in the catalog task record so that people can open a change record from a request. The request often comes with catalog variables and I need to copy them to the change request's description. Here's a snippet of code that works: The part that is missing is the instantiation of the change object with Glide Record to create the new change request, and the insertion afterward.
var lov = "\nList of Variables from Requested Item"; // lov = list of variables
for (var prop in current.parent.variables )
{
lov = lov + "\n" + prop + " = " + current.parent.variables[prop].getDisplayValue();
}
change.description = change.description + lov;
--------------- new edits below this line ------------------------------------
The solution above copies the variables in a somewhat random way. I decided to list them in a sorted order.
That way, with "intelligent variable names", like items could be sorted together.
The following code will copy the variables to the change.description field as the above examble:
I'm embarrassed to say how long it took me to figure this out and I invite you to show me an easier way to do this.
Again, this is missing is the instantiation of the change object with Glide Record to create the new change request, and the insertion afterward.
The code:
var lov = "\n\n===== List of Variables from Requested Item (" + current.parent.number + ") =====";
var index = 0;
var array = [];
for (var prop in current.parent.variables )
{
array[index] = prop;
index++;
}
var sorted = array.sort();
for ( x = 0; x<sorted.length; x++)
{
var key = sorted[x];
var value = current.parent.variables[key].getDisplayValue();
var line = "\n-> variable " + key + " = " + value;
if ( /\n/m.test(value) )
{
line = "\n-> variable " + key + " (multi-line) follows: --\n" + value + "\n<--- end of multi line variable " + key + " ---";
}
lov = lov + line;
}
change.description = "From " + current.parent.number + " -> " + current.number + ": " + current.short_description + "\n" + current.description + lov;