Order Guide and Workflow Lookup Issues When Submitted via Inbound Action

Stephen59
Tera Contributor

I have created a Catalog item configured as an Order Guide that uses four rules to generate four different Requested Items and associated Catalog Tasks, depending on specific conditions. This setup works as expected when users submit requests through the Service Portal.

 

However, I’m encountering issues when trying to submit requests via an Inbound Action:

 

Issue 1 – Submitting an Order Guide via Inbound Action

  • When submitting the Order Guide through an Inbound Action:
  • The Request and Requested Items are being created.
  • However, the associated Catalog Tasks are not being generated.
  • Additionally, the Short Description and Description defined in the workflow lookups are not being applied.

Issue 2 – Submitting a Catalog Item via Inbound Action
I have also tested submitting a standalone Catalog Item with four workflow lookups. When using the Inbound Action:

 

  • The Request, Requested Item, and Catalog Task are created.
  • However, the Short Description and Description for all Catalog Tasks are incorrectly being pulled from only the first workflow lookup (e.g., the one with order = 100).
  • The other workflow lookups are being ignored in terms of their descriptions.
3 REPLIES 3

Ankur Bawiskar
Tera Patron
Tera Patron

@Stephen59 

how are you submitting order guide via inbound action?

share that script

If my response helped please mark it correct and close the thread so that it benefits future readers.

Regards,
Ankur
Certified Technical Architect  ||  9x ServiceNow MVP  ||  ServiceNow Community Leader

Below is the inbound action script 

 

(function runAction(current, event, email, logger, classifier) {

// Helper: Extract a field value from the email body
function extract(field) {
return body.match(new RegExp(field + ":\\s*(.*)", "i"))?.[1]?.trim();
}

var body = email.body_text;

// Extract all variables from the email
var leaversName = extract("Leaver's name");
var assignmentNumber = extract("Assignment number");
var emailAddress = extract("Email address \\(test\\.net\\)");
var alternativeEmail = extract("Alternative email address");
var addressHome = extract("Address \\(home\\)");
var preferredContactNumber = extract("Preferred contact number");
var empDirectorate = extract("Directorate");
var subDirectorate = extract("Sub directorate");
var empTeam = extract("Team");
var jobTitle = extract("Job title");
var lineManagerName = extract("Line manager name");
var lineManagerEmail = extract("Line manager email");
var officeLocation = extract("Office location");
var leavingDate = extract("Leaving Date");
var lastDay = extract("Last day in the office");
var wholeTimeEquivalent = extract("WTE \\(whole time equivalent\\)");
var staffType = extract("Staff type");
var reasonForLeaving = extract("Reason for leaving");
var leaverType = extract("Leaver type");
var exitInterview = extract("Has an exit interview taken place\\?");
var costCentre = extract("Cost centre");
var anyEquipment = extract("Do you have any IT equipment\\?");
var workLaptop = extract("Do you have a laptop\\?");
var workMobile = extract("Do you have a mobile\\?");
var workMonitor = extract("Do you have a monitor\\(s\\)\\?");
var anyOther = extract("Other");

// Catalog Item sys_id (replace with yours)
var catalogItemSysId = 'cb28fd821be9a210c8f8fee5d34bcbcb';

// Initialize a shared Cart (to keep all RITMs under one REQ)
var cart = new Cart();

// Define shared variables
var commonVars = {
leaver_s_name: leaversName,
assignment_number: assignmentNumber,
email_address_test_net: emailAddress,
alternative_email_address: alternativeEmail,
address_home: addressHome,
preferred_contact_number: preferredContactNumber,
directorate: empDirectorate,
sub_directorate: subDirectorate,
team: empTeam,
job_title: jobTitle,
line_manager_name: lineManagerName,
line_manager_email: lineManagerEmail,
office_location: officeLocation,
leaving_date: leavingDate,
last_day_in_the_office: lastDay,
wte_whole_time_equivalent: wholeTimeEquivalent,
staff_type: staffType,
reason_for_leaving: reasonForLeaving,
leaver_type: leaverType,
has_an_exit_interview_taken_place: exitInterview,
cost_centre: costCentre,
other: anyOther
};

// Create the base RITM (always created)
createCartItem(Object.assign({}, commonVars, {
do_you_have_any_it_equipment: anyEquipment,
do_you_have_a_laptop: workLaptop,
do_you_have_a_mobile: workMobile,
do_you_have_a_monitor_s: workMonitor
}));

// Conditionally create Laptop RITM
if (workLaptop && workLaptop.toLowerCase() === 'yes') {
createCartItem(Object.assign({}, commonVars, {
do_you_have_a_laptop: 'Yes'
}));
}

// Conditionally create Mobile RITM
if (workMobile && workMobile.toLowerCase() === 'yes') {
createCartItem(Object.assign({}, commonVars, {
do_you_have_a_mobile: 'Yes'
}));
}

// Conditionally create Monitor RITM
if (workMonitor && workMonitor.toLowerCase() === 'yes') {
createCartItem(Object.assign({}, commonVars, {
do_you_have_a_monitor_s: 'Yes'
}));
}

// Place the order (creates one REQ with all RITMs)
var req = cart.placeOrder();
gs.log("Leaver request submitted from email. REQ: " + req.request.number);

// ---------------------------------------
// Helper function to add a catalog item to the cart
function createCartItem(variablesObj) {
var item = new GlideRecord('sc_cat_item');
if (!item.get('sys_id', catalogItemSysId)) {
gs.error('Catalog item not found: ' + catalogItemSysId);
return;
}

var cartItem = cart.addItem(item.getUniqueValue());

for (var key in variablesObj) {
if (variablesObj.hasOwnProperty(key) && variablesObj[key] != null) {
cart.setVariable(cartItem, key, variablesObj[key]);
}
}

gs.log('Created RITM with vars: ' + JSON.stringify(variablesObj));
}

})(current, event, email, logger, classifier);

Stephen59
Tera Contributor

I have finally resolved the issue...