Use PDIs? Take our 5-minute survey to help shape the PDI roadmap.

Show variable from variable set of catalog item in approval email

Nicholas Hromya
Giga Guru

Hello everyone,

As an approver, I want to see the variable requested_for in my approval email.

This requested_for is in my variable set named SNAR_1

 

I have tried the following without results.  It seems there should be an easier way.  I think the variable set is what I don't understand.

 
var request = current.sysapproval;
 var notificationUtil = new RequestNotificationUtil();
    var requestDetails = notificationUtil.getRequestDetails(request, request, true);
    var showRequestedFor = requestDetails.showRequestedFor;
    var tasks = requestDetails.tasks;
    var totalTasks = requestDetails.totalTasks;


    template.print('<div style="font-size: 15pt; line-height:30px; padding-bottom:16px"><b>About this request</b></div>');

    var priceDisplay = gs.getProperty('glide.sc.price.display');
    var showRequestPrice = false;
    if (requestDetails.totalTasks > 1 && priceDisplay !== 'never' && request.price > 0) {
        showRequestPrice = true;
    }
    var showOpenedBy = false;

    if (request.opened_by.toString() !== request.requested_for.toString()) {
        showOpenedBy = true;
    }
    var requestItemsPadding = 'padding-top:16px;';
    if (showOpenedBy || showRequestedFor || showRequestPrice) {
        template.print('<div style="padding-bottom:16px">');

        if (showRequestedFor) {
            template.print('<div style="' + fontSize + lineHeight + '">Requested for: ' + '<b>' + request.requested_for.name + '</b></div>');
        }
        if (showOpenedBy) {
            template.print('<div style="' + fontSize + lineHeight + '">Opened by: ' + '<b>' + request.opened_by.name + '</b></div>');
        }
        if (showRequestPrice) {
            var recurringPriceText = notificationUtil.gerRecurringPriceRollup(request);
            template.print('<div style="' + fontSize + lineHeight + '">Total price: ' + '<b>' + request.price.getDisplayValue() + '</b><span style="font-size:14px;font-weight: 600">' + recurringPriceText + '</span></div>');
        }
        template.print('</div>');
    } else {
        requestItemsPadding = '';
    }

    if (requestDetails.totalTasks > 1) {
        template.print('<div style="font-size: 12pt;font-weight:600;' + requestItemsPadding + '">Requested items (' + requestDetails.totalTasks + ')</div>');
    }
    tasks.forEach(function(task, index) {
        var borderBottom = 'border-bottom:1px solid #DADDE2';
        if (requestDetails.totalTasks > 1) {
            template.print('<div style="padding-top:16px;padding-bottom:16px;');
        } else {
            template.print('<div style="padding-bottom:16px;');
        }
        if (requestDetails.totalTasks > requestDetails.tasks.length || (index + 1 < requestDetails.tasks.length)) {
            template.print(borderBottom);
        }
        template.print('">');
        template.print('<div style="' + fontSize + lineHeight + '">Requested item number: <b>' + task.requestNumber + '</b></div>');
        template.print('<div style="' + fontSize + lineHeight + '">Short description: <b>' + task.item + '</b></div>');
        if (task.variables.length > 0) {
            notificationUtil.setRequestItemVariablestoTemplate(task, template);
        }
        if (!showRequestedFor) {
            template.print('<div style="' + fontSize + lineHeight + '">Requested for: <b style="font-weight:600">' + task.requestedFor + '</b></div>');
        }
        if (task.showQuantity) {
            template.print('<div style="' + fontSize + lineHeight + '">Quantity: <b>' + task.quantity + '</b></div>');
        }
        notificationUtil.setPricingtoTemplate(task, template);
        template.print('</div>');
    });
    if (totalTasks > 3) {
        template.print('<div style="padding-bottom:16px;padding-top:16px' + fontSize + lineHeight + '"><a style="color:#3C59E7" href="' + requestUrl + '">');
        template.print(gs.getMessage('View all items'));
        template.print('</a></div>');
    }

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

 

8 REPLIES 8

Suryansh Verma
Mega Sage

@Nicholas Hromya 

 

If the variable belongs to a Variable Set, you don't need to recreate it directly on the Catalog Item. Open the variable inside the Variable Set and enable Visible on Summaries under the Availability section. ServiceNow documents that variables with this option enabled are shown on both the Service Portal RITM ticket page and the Approval page.

Also verify that the approver satisfies any Read roles configured on the variable and that the variable actually contains a value on the RITM.

Global does not need to be enabled for this requirement, that option controls availability to Catalog Tasks/workflows rather than approval summaries.

If this is a Multi-Row Variable Set rather than a normal single-row Variable Set, mention that separately because MRVS rendering and scripting are handled differently.

 

If my response helped, please mark it as correct and close the thread, this helps future readers find the solution faster!!!

The variable in the variable set is a reference field.

Chetna_Aggarwal
Tera Contributor

 

If requested_for is a catalog variable in the SNAR_1 variable set, access it through the variables object rather than request.requested_for.

For example:

 

 
current.sysapproval.variables.requested_for
 

That works!