Catalog Item: Show variable value in email only for selected Line of Business

VojjalaS
Tera Contributor

Hi All,

I am working on a Catalog Item in ServiceNow and need some help with displaying catalog variable values correctly in an email notification.

Requirement:

I have a Catalog Item with the following variables:

  • Line of Business (Select Box): Enterprise, Facilities, Auto, PI, Claims, Life, Systems, Security
  • System Services (Select Box): Red, Yellow, Green

Once the Catalog Item is requested, an email notification is triggered. In the email, I need to display a table like below:

Systems and Services Status

Line of Business Status

Enterprise 
Facilities 
Auto 
PI 
Claims 
Life 
Systems 
Security 

Expected Behavior:

  • Only the selected Line of Business should show the corresponding System Services status (e.g., , 🟡, 🔴).
  • All other Line of Business rows should remain empty.
  • Example: If user selects Enterprise and Green, only Enterprise should show and all other rows should be blank.

    Is there a recommended way to dynamically map catalog variable values like this?

    Any guidance or sample script would be really helpful.

    Thanks in advance!

1 REPLY 1

lochuynh33
Tera Guru

Hi @VojjalaS ,
Please try attaching this mail script if it works for you.

 

(function runMailScript(current, template, email, email_action, event) {

 

    if (!current || !current.sys_id) {
        return;
    }

 

    var selectedLOB = current.variables.line_of_business + '';
    var selectedStatus = current.variables.system_services + '';

 

    var lobList = [
        "Enterprise",
        "Facilities",
        "Auto",
        "PI",
        "Claims",
        "Life",
        "Systems",
        "Security"
    ];

 

    var statusIcon = "";
    switch (selectedStatus) {
        case "Green":
            statusIcon = "";
            break;
        case "Yellow":
            statusIcon = "🟡";
            break;
        case "Red":
            statusIcon = "🔴";
            break;
        default:
            statusIcon = "";
    }

 

    var html = '';
    html += '<h3>Systems and Services Status</h3>';
    html += '<table border="1" cellpadding="6" cellspacing="0">';
    html += '<tr><th>Line of Business</th><th>Status</th></tr>';

 

    for (var i = 0; i < lobList.length; i++) {
        html += '<tr>';
        html += '<td>' + lobList[i] + '</td>';

 

        if (lobList[i] === selectedLOB) {
            html += '<td align="center">' + statusIcon + '</td>';
        } else {
            html += '<td>&nbsp;</td>';
        }

 

        html += '</tr>';
    }

 

    html += '</table>';

 

    template.print(html);

 

})(current, template, email, email_action, event);
 

If this response was helpful, please consider marking it as Correct and Helpful. You may mark more than one reply as an accepted solution.