How to only show the variables that has value in Short Description

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 07:08 AM
I am Tasked to only show the Variables that was Mark as True, or has Values.
Some of my Variables are Reference Fields so the .getDisplayValue() has to be used to add it to the Short Description
Using this type of script works when the Variables are few
current.description = "Action: " + current.variables.action
+ '\n' + "Date Required: " + current.variables.date_required
+ '\n' + "Setup User Like: " + current.variables.set_up_like.getDisplayValue()
+ '\n' + "Requestor's Call Back Number: " + current.variables.Phone_Number
But when having larger numbers of Variables, this basic idea will not work, so now looking for a way to only move the variable to short.description if it has value.
So I was trying something like this:
Boolean getBooleanValue(fieldName)
- Returns false if the field value is false or undefined, otherwise returns true.
- Parameters:
- fieldName - specifies the name of the field.
- Returns:
- Boolean - the boolean value of the field.
if (getBooleanValue(current.variables.action) != null) {
current.description = "Action: " + current.variables.action;
if (getBooleanValue(current.variables.date_required) != null) {
current.description = "Date Required: " + current.variables.date_required;
if (getBooleanValue(current.variables.set_up_like) != null) {
current.description = "Setup User Like: " + current.variables.set_up_like.getDisplayValue();
if (getBooleanValue(current.variables.Phone_Number) != null) {
current.description = "Requestor's Call Back Number: " + current.variables.Phone_Number;
}
}
}
}
But this is not working. Can anyone please tell me what I am doing that is incorrect, or point me in right direction.
I am doing this from the Workflow Editor using the Core Utilities Run Script Box.
The main idea is so the end user will see what was entered from the Request in the Short Description, without showing all the Variables.
- Labels:
-
Best Practices
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 12:14 PM
Does this look right? I'm getting error withing the code.
var variablesNames = [];
var item = new GlideappCatalogItem.get(current.3406f8cb4fcb9e40bf23f7e18110c713); //sysid of the catalog item cat_item field on RITM refers to Catalog Item - Error Red Dot ( Unexpected '.'. )
var variables = item.getVariables(); - Error Orange Dot ( expected ')' and instead saw 'var' and Missing Semicolon
while(variables.next())
{
// pushing into an array all the variable names
variablesNames.push(current.variables.action.toString());
variablesNames.push(current.variables.date_required.toString());
variablesNames.push(current.variables.set_up_like.getDisplayValue().toString());
variablesNames.push(current.variables.Phone_Number.toString());
variablesNames.push(current.variables.user_type.getDisplayValue().toString());
variablesNames.push(current.variables.Employee_Number.toString());
variablesNames.push(current.variables.Current_Name.toString());
variablesNames.push(current.variables.Name_Changed.toString());
variablesNames.push(current.variables.requested_for.getDisplayValue().toString());
variablesNames.push(current.variables.chk_network.toString());
variablesNames.push(current.variables.chk_Epic.toString());
variablesNames.push(current.variables.chk_email.toString());
variablesNames.push(current.variables.chk_create_main_wo.toString());
variablesNames.push(current.variables.chk_plant_maint.toString());
variablesNames.push(current.variables.chk_time_keeping.toString());
}
// now iterate over the variables to know if they have true or not empty
for(var i=0;i<variablesNames.length;i++){
if(current.variables[variablesNames[i]] != '' && current.variables[variablesNames[i]] != 'false' && ){ // this is the condition you can add
Error Red Dot ( expected an identifier and saw ')' and Expected ')' to match '(' from line 27 and instead saw '{' )
gs.print('Variable name is:'+variablesNames[i] + ' value is: ' + current.variables[variablesNames[i]]);
} Error Red Dot (Unrecoveable Syntax error ( 28% Scanned)
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 12:16 PM
(current.3406f8cb4fcb9e40bf23f7e18110c713) - Should be (current.sysid3406f8cb4fcb9e40bf23f7e18110c713)

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 12:20 PM
} had a extra - Removed

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 12:50 PM
// now iterate over the variables to know if they have true or not empty
for(var i=0;i<variablesNames.length;i++){
if(current.variables[variablesNames[i]] != '' && current.variables[variablesNames[i]] != 'false' && ){ // this is the condition you can add
Error Red Dot ( expected an identifier and saw ')' and Expected ')' to match '(' from line 27 and instead saw '{' )
current.description('Action:'+ variablesNames[i] + ' value is: ' + current.variables[variablesNames[i]]);
Changed it to:
for (var i=0;i<variablesNames.length;i++) {
if (current.variables[variablesNames[i]] != '' && current.variables[variablesNames[i]] != 'false' ); // this is the condition you can add
current.description('Action:' + variablesNames[i] + ' value is: ' + current.variables[variablesNames[i]]);
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-08-2017 06:45 AM
Script is not working - Help Please
Can someone tell me what I'm doing wrong
var variablesNames = [];
var item = new GlideappCatalogItem.get(current.sysid3406f8cb4fcb9e40bf23f7e18110c713); //sysid of the catalog item cat_item field on RITM refers to Catalog Item
var variables = item.getVariables();
while(variables.next())
{
// pushing into an array all the variable names
variablesNames.push(current.variables.action.toString());
variablesNames.push(current.variables.date_required.toString());
variablesNames.push(current.variables.set_up_like.getDisplayValue().toString());
variablesNames.push(current.variables.Phone_Number.toString());
variablesNames.push(current.variables.user_type.getDisplayValue().toString());
variablesNames.push(current.variables.Employee_Number.toString());
variablesNames.push(current.variables.Current_Name.toString());
variablesNames.push(current.variables.Name_Changed.toString());
variablesNames.push(current.variables.requested_for.getDisplayValue().toString());
variablesNames.push(current.variables.chk_network.toString());
variablesNames.push(current.variables.chk_Epic.toString());
variablesNames.push(current.variables.chk_email.toString());
variablesNames.push(current.variables.chk_create_main_wo.toString());
variablesNames.push(current.variables.chk_plant_maint.toString());
variablesNames.push(current.variables.chk_time_keeping.toString());
}
// now iterate over the variables to know if they have true or not empty
for (var i=0;i<variablesNames.length;i++) {
if (current.variables[variablesNames[i]] != '' && current.variables[variablesNames[i]] != 'false' ); // this is the condition you can add
current.description('Action:' + variablesNames[i] + ' value is: ' + current.variables[variablesNames[i]]);
}