Help with scripting catalog variables in Flow Designer for work notes formatting

barbaratosetto
Tera Contributor

Hi everyone,

I'm building a flow in Flow Designer to generate a formatted message for work notes in a catalog task based on user input from variables. Here's my current script:

 

// get necessary variables
var deliveryMethod = fd_data.trigger.request_item.variables.delivery_method + '';
var shippingAddress = fd_data.trigger.request_item.variables.shipping_address || '';
var location = fd_data.trigger.request_item.variables.user_location.display_value || '';
var pickUpDate = fd_data.trigger.request_item.variables.pick_up_date || '';
var wbsCode = fd_data.trigger.request_item.variables.wbs_code || '';
var message = '';

if (deliveryMethod === 'ship_to_address') {
message += 'Delivery Method: Ship to Address\n';
message += shippingAddress + '\n';
message += '\nWBS Code: ' + wbsCode;
} else {
message += 'Delivery Method: Office Pick-Up\n';
message += 'Please coordinate with the user to arrange a pick-up date in the office: ' + location + '\n';
message += 'Scheduled Pick-Up Date/Time: ' + pickUpDate + '\n';
}

return message;
 

However, when I run the flow:

  • The location and pick-up date are not displaying correctly (they show up blank in the message).

  • Other variables like shipping_address and wbs_code are working fine.

I've verified that the user_location variable is a reference to cmn_location and pick_up_date is a Date/Time type variable.

 

Has anyone encountered this before?


Is there a better way to pull the values from catalog variables in this context?

 

Any help or best practice advice would be appreciated!

 

Thanks in advance 😊

 

 

 

1 ACCEPTED SOLUTION

Cheikh Ahmadou
Tera Guru

I think that it is happening because:

1. Reference variables

When accessing request_item.variables.user_location, you’re getting the sys_id, not a GlideRecord or full object.

So:
fd_data.trigger.request_item.variables.user_location.display_value
will return undefined or blank, because user_location is a string (sys_id), not an object with .display_value

2. Date/Time variables

Variables like pick_up_date might not be directly accessible as raw text — sometimes you need to ensure they’re cast properly or referenced using .toString().


I will propose to test below code:

// Get the variables safely as strings
var deliveryMethod = fd_data.trigger.request_item.variables.delivery_method + '';
var shippingAddress = fd_data.trigger.request_item.variables.shipping_address || '';
var wbsCode = fd_data.trigger.request_item.variables.wbs_code || '';

// For user_location (reference), get display value via script
var locationSysId = fd_data.trigger.request_item.variables.user_location;
var location = '';
if (locationSysId) {
  var locGR = new GlideRecord('cmn_location');
  if (locGR.get(locationSysId)) {
    location = locGR.getDisplayValue(); // Or locGR.name
  }
}

// For pick_up_date (date/time), convert to string
var pickUpDate = fd_data.trigger.request_item.variables.pick_up_date;
if (pickUpDate) {
  pickUpDate = pickUpDate + ''; // Force to string
}

var message = '';

if (deliveryMethod === 'ship_to_address') {
  message += 'Delivery Method: Ship to Address\n';
  message += shippingAddress + '\n';
  message += '\nWBS Code: ' + wbsCode;
} else {
  message += 'Delivery Method: Office Pick-Up\n';
  message += 'Please coordinate with the user to arrange a pick-up date in the office: ' + location + '\n';
  message += 'Scheduled Pick-Up Date/Time: ' + pickUpDate + '\n';
}

return message;

 

View solution in original post

1 REPLY 1

Cheikh Ahmadou
Tera Guru

I think that it is happening because:

1. Reference variables

When accessing request_item.variables.user_location, you’re getting the sys_id, not a GlideRecord or full object.

So:
fd_data.trigger.request_item.variables.user_location.display_value
will return undefined or blank, because user_location is a string (sys_id), not an object with .display_value

2. Date/Time variables

Variables like pick_up_date might not be directly accessible as raw text — sometimes you need to ensure they’re cast properly or referenced using .toString().


I will propose to test below code:

// Get the variables safely as strings
var deliveryMethod = fd_data.trigger.request_item.variables.delivery_method + '';
var shippingAddress = fd_data.trigger.request_item.variables.shipping_address || '';
var wbsCode = fd_data.trigger.request_item.variables.wbs_code || '';

// For user_location (reference), get display value via script
var locationSysId = fd_data.trigger.request_item.variables.user_location;
var location = '';
if (locationSysId) {
  var locGR = new GlideRecord('cmn_location');
  if (locGR.get(locationSysId)) {
    location = locGR.getDisplayValue(); // Or locGR.name
  }
}

// For pick_up_date (date/time), convert to string
var pickUpDate = fd_data.trigger.request_item.variables.pick_up_date;
if (pickUpDate) {
  pickUpDate = pickUpDate + ''; // Force to string
}

var message = '';

if (deliveryMethod === 'ship_to_address') {
  message += 'Delivery Method: Ship to Address\n';
  message += shippingAddress + '\n';
  message += '\nWBS Code: ' + wbsCode;
} else {
  message += 'Delivery Method: Office Pick-Up\n';
  message += 'Please coordinate with the user to arrange a pick-up date in the office: ' + location + '\n';
  message += 'Scheduled Pick-Up Date/Time: ' + pickUpDate + '\n';
}

return message;