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 07:17 AM
Hi Mark,
Could you try using.
var desc='';
if (getBooleanValue(current.variables.action) != null) {
desc = "Action: " + current.variables.action;
if (getBooleanValue(current.variables.date_required) != null) {
desc = desc+ " Date Required: " + current.variables.date_required;
if (getBooleanValue(current.variables.set_up_like) != null) {
desc = desc+ " Setup User Like: " + current.variables.set_up_like.getDisplayValue();
if (getBooleanValue(current.variables.Phone_Number) != null) {
desc = desc+ " Requestor's Call Back Number: " + current.variables.Phone_Number;
current.description=desc;
}
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 07:25 AM
Hi Mark,
first fetch all the variables for this catalog item and then check for whether value is true and not empty and not undefined and then use
Mark Correct if this solves your issue and also hit Like and Helpful if you find my response worthy based on the impact.
Thanks
Ankur
Ankur
✨ Certified Technical Architect || ✨ 9x ServiceNow MVP || ✨ ServiceNow Community Leader

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 07:29 AM
Did not work for me.
var desc="";
if (getBooleanValue(current.variables.action) != null) {
desc = "Action: " + current.variables.action;
if (getBooleanValue(current.variables.date_required) != null) {
desc = "Date Required: " + current.variables.date_required;
if (getBooleanValue(current.variables.set_up_like) != null) {
desc = "Setup User Like: " + current.variables.set_up_like.getDisplayValue();
if (getBooleanValue(current.variables.Phone_Number) != null) {
desc = "Requestor's Call Back Number: " + current.variables.Phone_Number;
if (getBooleanValue(current.variables.user_type) != null) {
desc = "User Type: " + current.variables.user_type.getDisplayValue();
if (getBooleanValue(current.variables.Employee_Number) != null) {
desc = "User Employee Number: " + current.variables.Employee_Number;
if (getBooleanValue(current.variables.Current_Name) != null) {
desc = "Current Name: " + current.variables.Current_Name;
if (getBooleanValue(current.variables.Name_Changed) != null) {
desc = "Name Changed to: " + current.variables.Name_Changed;
if (getBooleanValue(current.variables.chk_react_prev) != null) {
desc = "Reactivate / Previous: " + current.variables.chk_react_prev;
if (getBooleanValue(current.variables.chk_network) != null) {
desc = "Network: " + current.variables.chk_network;
}
}
}
}
}
}
}
}
}
}

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎09-07-2017 07:30 AM
How would I Script this?
first fetch all the variables for this catalog item and then check for whether value is true and not empty and not undefined and then use
Mark