- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2016 01:51 PM
Hello All,
I hope you are having a wonderful Monday! I needed to reach out to the community for some assistance and see if anyone can help me figure my problem out. I need to take all the variables and pass them in to the "Description" field in the task (in the workflow). I need to make sure make sure they display in the "description" field in a certain order, skip anything that is null, and each variable is in a new line, etc. The variables are all types (reference, integers, check box, string, etc.) This item has about 35/40 variables but I will provide how I have coded a few of them below. I am getting syntax errors and also the code is not really working.
1) is there a better way that what I have present below?
2) Can you please help me perfect my code below and explain what I might be doing wrong?
Example of my code (have to code this for about 38 variables due to them being displayed in a certain order):
//create a variable that will be appended to as you check each request variable for a value
var new_description;
var event_name = current.variables.event_name;
var event_date_start = current.variables.event_date_start;
var event_time_start = current.variables.event_time_start;
var requested_by = current.variables.requested_by;
if (null !=event_name) {
new_description = (new_description && "Name of Event: " && event_name.toString());
}
if (null !=event_date_start) {
new_description = \n(new_description && "Date Event Will Begin: " && event_date_start.toString());
}
if (null !=event_time_start) {
new_description = \n(new_description && "Daily Start Time: " && event_time_start.toString());
}
if (null !=requested_by) {
new_description = \n(new_description && "Requested By: " && requested_by.toString());
}
current.description = new_description;
***not passing the actual variables over because the page looks too busy for our customer and is overwhelming. that would have taken seconds to do but they wanted me to pass the value into the description field for their full-fillers to be able to read. ***
Solved! Go to Solution.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-25-2016 01:59 PM
I just did a similar type of thing in a workflow, creating a task with the summary of the variables in the description field:
var gr = new GlideRecord("sc_req_item");
gr.addQuery("request", current.request.sys_id);
gr.query();
while(gr.next()) {
// Get Owned Variables for Requested Item and sort by Order
var ownvar = new GlideRecord('sc_item_option_mtom');
ownvar.addQuery('request_item.number', gr.number);
ownvar.addQuery('sc_item_option.value','!=','');
ownvar.orderBy('sc_item_option.order');
ownvar.query();
var items = "Summary of " + gr.number + ": " + gr.cat_item.getDisplayValue() + "\n\n";
while(ownvar.next()) {
var field = ownvar.sc_item_option.item_option_new;
var fieldValue = ownvar.sc_item_option.item_option_new.name;
// Print variable name
items += field.getDisplayValue() + ": " + gr.variables[fieldValue].getDisplayValue() + "\n";
}
}
task.description = items;
Try that and see if it works for what you need. It does skip null variables and does an 'OrderBy' based on the Order number of the variable. It ends up looking something like this:
++++++
Summary of RITM0016419: Unitize Rental/RPO Unit
Equipment Number: 0987
ETM Order Number: 0987
Tag Number: 05-698
Is this an asset?: No
Characteristic Value: Test
Characteristic Name: Test
Equipment Description: Test
Brand Name: Test
Model Number: Test
Model Year: Test
Serial Number: Test
++++++
Hope that helps!
Cheers,
Tim

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
11-19-2019 08:25 AM
This was fantastic!, In addition to excluding empty variable, I also excluded Breaks and Container Start/Split/End
//Excluding empty variables, breaks, and containers
ownvar.addQuery('sc_item_option.value','!=','');
ownvar.addQuery('sc_item_option.item_option_new.type','DOES NOT CONTAIN','Container');
ownvar.addQuery('sc_item_option.item_option_new.type','!=','Break');

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
04-26-2016 10:03 AM
You'll need to dot-walk to the 'name' for the reference field:
var requested_by = current.variables.requested_by.name.toString();
Also, declare the 'new_description' as empty first:
var new_description = '';
I'm not sure why it's duplicating, though.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-04-2016 03:48 PM
Hi Tim,
I hope you are doing well. I wanted to provide an update to what you were helping me figure out. Below is the script I ended up going forward with. It works really well and the way I want it to EXCEPT for one thing. I can not figure out why it just wont work. I tried to practice the logic of the script in scripts background and it works there but in the actual RITM it does not. Please let me know if you see something that I might not be doing correctly below : I am trying to figure out why are the boolean type variables are not being captured. Anything that has the "!" before the "current" are my boolean type variables.
Thank you in advance for your help and time again:
***Script being used : Boolean Variables are being ignored***
var new_description = "";
if(current.variables.event_name != ''){
new_description += "Name of Event:" + current.variables.event_name + "\n";
}
if(current.variables.event_date_start != ''){
new_description += "Date Event Will Begin:" + current.variables.event_date_start + "\n";
}
if(current.variables.event_time_start != ''){
new_description += "Daily Start Time:" + current.variables.event_time_start + "\n";
}
if(current.variables.requested_by != ''){
new_description += "Requested By:" + current.variables.requested_by.getDisplayValue() + "\n";
}
if(current.variables.requested_for != ''){
new_description += "Requested For:" + current.variables.requested_for.getDisplayValue() + "\n";
}
if(current.variables.special_instructions != ''){
new_description += "Special Instructions:" + current.variables.special_instructions + "\n";
}
if(current.variables.event_time_end != ''){
new_description += "Daily End Time:" + current.variables.event_time_end + "\n";
}
if(current.variables.event_date_end != ''){
new_description += "Date Event Will End:" + current.variables.event_date_end + "\n";
}
if(current.variables.conference_id != ''){
new_description += "Conference ID:" + current.variables.conference_id + "\n";
}
if(current.variables.conference_phone != ''){
new_description += "Dialin Number:" + current.variables.conference_phone + "\n";
}
if(current.variables.conference_passcode != ''){
new_description += "Passcode:" + current.variables.conference_passcode + "\n";
}
if(!current.variables.use_online_meeting){
new_description += "I will use Sametime:" + current.variables.use_online_meeting + "\n";
}
if(!current.variables.need_computer_audio){
new_description += "Need Computer Audio:" + current.variables.need_computer_audio + "\n";
}
if(!current.variables.need_computer){
new_description += "I will need to use the room's computer:" + current.variables.need_computer + "\n";
}
if(!current.variables.own_computer){
new_description += "I will be using my own computer:" + current.variables.own_computer + "\n";
}
if(!current.variables.need_navigator){
new_description += "I require a slide navigator:" + current.variables.need_navigator + "\n";
}
if(current.variables.laptop_video_connection != 0){
new_description += "Number of Laptop Video Connections Required:" + current.variables.laptop_video_connection + "\n";
}
if(!current.variables.projector){
new_description += "Number of Projectors Required:" + current.variables.projector + "\n";
}
if(current.variables.microphone != 0){
new_description += "Number of Microphones Required:" + current.variables.microphone + "\n";
}
if(!current.variables.need_lapel_mic){
new_description += "Require Lapel/Lavalier Mic:" + current.variables.need_lapel_mic + "\n";
}
if(!current.variables.need_avtech){
new_description += "I need an AV Technician for the Duration:" + current.variables.need_avtech + "\n";
}
if(!current.variables.need_lectern){
new_description += "I will need a Lectern for this Event:" + current.variables.need_lectern + "\n";
}
if(current.variables.flipstand!= 0){
new_description += "Number of Flip Chart Stands With Paper:" + current.variables.flipstand + "\n";
}
current.description += new_description;

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 06:32 AM
Syed,
In the task description where these boolean variables are supposed to be displayed, is the space just blank? Are these the Yes/No type of fields?
Tim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
05-05-2016 06:48 AM
as of right now, they do not show up at all. They basically get skipped. However, if I change " if(!current.variables.need_lapel_mic)" to if(current.variables.need_lapel_mic != false) the "column name" shows up but it passes items whether it is false or true. I have given all my variables default values as well ( in this variable type = false).
The goal is to pick up my variables and if the default value is false, 0, or blank to skip the variable. it is working except for the Boolean items.