How to restrict category variable for each catalog item in the notification

vamshi2
Tera Contributor

Hi Team 

 

i am bringing all the variables in notification using below mail script

 

(function runMailScript( /* GlideRecord */ current, /* TemplatePrinter */ template,
    /* Optional EmailOutbound */
    email, /* Optional GlideRecord */ email_action,
    /* Optional GlideRecord */
    event) {

    // Add your code here
    template.print("<b>Summary of Request</b><br>");
    var item = new GlideRecord("sc_req_item");
    item.addQuery('request',current.sys_id);
    item.query();
    if (item.next()) {
        var set = new GlideappVariablePoolQuestionSet();
        set.setRequestID(item.sys_id);
        set.load();
        var vs = set.getFlatQuestions();
        // Iterate through all variables
        for (var i = 0; i < vs.size(); i++) {
            var label = vs.get(i).getLabel(); // Get the label
            var value = vs.get(i).getDisplayValue(); // Get the value
            // Print only if the variable has a value
            if (value) {
                // Split value into lines and process each line separately
                var lines = value.split("\n"); // Split by newline characters
                template.print(label + ": ");
                // Print each line with <br>
                for (var j = 0; j < lines.length; j++) {
                    template.print(lines[j] + "<br>");
                }
            }
        }
    }

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

 

 

but the thing is i need to restrict category data variable that is hidden on form which is used for other purpose but the value in this category data variable is populating using category variable in the form with the help of on submit client script

 

in the notification i am getting two variables category and category data so please suggest how to restrict category data variable

6 REPLIES 6

Ankur Bawiskar
Tera Patron
Tera Patron

@vamshi2 

So you don't the category variable data to be printed in email?

if yes then update as this

            if (value && label != 'give your label for your category variable') {
 

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

Hi @Ankur Bawiskar 

 

Thanks for quick response 

 

but it is global change so cannot identify variable name

 

so i need solution to show variable data which is displayed on catalog request form and need to restrict all variable data which is hidden

@vamshi2 

it's very difficult to determine if variable was hidden or not from email script which is server side.

variable shown/hidden is client side

The max you can do is if the value is not empty then print it

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

@vamshi2 

Hope you are doing good.

Did my reply answer your question?

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