- 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
02-22-2016 06:41 AM
which version of ServiceNow are you running?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-24-2016 01:07 AM
Fuji
Vriendelijke groeten,
Bien í vous,
Jan Vercauteren
Channel Manager
ING Belgií«, HR Communication & Branding
SMW 0.50
T +32 2 738 45 20, M +32 497 68 25 84
jan.vercauteren@ing.be<mailto:jan.vercauteren@ing.be>
HR Contact Helpdesk: Tel. + 32 2 738 66 66 Fax + 32 2 738 93 45
HR Intranet: http://www.be.intranet/eip/ingbeportal_hr/

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
03-28-2018 10:59 AM
Hi Oslova,
any chance that there is a more up to date version available?
Can't even save the script include due to script errors.
I'm not the deep down developer .. so hard for me to fix it.
I.e. the var noBlanks (line 40) has been defined before already (line38) .. etc.
I'm on Kingston P3 ...
Thank you!!!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
01-04-2022 02:58 AM
The below script is working ok however it is populating the variable Name (value e.g provide_justification) and not the Question (Label of the Variable e.g Please provide the justification).
Anyone who has got that resolved with the Variable Label??
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;