Join the #BuildWithBuildAgent Challenge! Get recognized, earn exclusive swag, and inspire the ServiceNow Community with what you can build using Build Agent.  Join the Challenge.

Hide field on email notification if that field is empty in catalog item.

abhaysingh98
Tera Contributor

Hi guys,

 

I have a requirement where catalog items have a price field, when this fields is filled in catalog item, then I would like to add this field to the approval email else I want this field to be hidden in approval mail.

I have created an email script to show this price field on email notification to the approver but I am not sure how to hide this field or cell value in email notification if price field is empty in catalog item.

 

 

7 REPLIES 7

That works only with fields that can be empty. Price fields always have a value. It can just be 0, but still the value is there.


Please mark any helpful or correct solutions as such. That helps others find their solutions.
Mark

Hi @Rajesh Chopade1 ,

 

I have to use this field on approval email i.e. on sysapproval_approver. Please check my email script and guide what changes needs to be done.

 

Hi @abhaysingh98 

try following script once, where I have taken care of price = 0 also -  as suggested by Mark.

// Check if the recurring_price field is not null/empty and not equal to 0
    if (current.sysapproval.recurring_price && current.sysapproval.recurring_price.getReferenceValue() != 0) {
        // Calculate the total recurring price
        var totalRecurringPrice = current.sysapproval.quantity * current.sysapproval.recurring_price.getReferenceValue();

        // Format the total price
        var formattedPrice = current.sysapproval.recurring_price.getReferenceCurrencyCode() + " " + parseFloat(totalRecurringPrice).toFixed(2);

        // Print the formatted price to the email template
        template.print("<p><strong>Price:</strong> " + formattedPrice + "</p>");
    }