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

@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

sunil maddheshi
Tera Guru

@vamshi2 

Can you try with below updated code

(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 name = vs.get(i).getName(); // Get the variable name
            var value = vs.get(i).getDisplayValue(); // Get the value
            
            // Skip the "Category Data" variable (modify as needed)
            if (name == "category_data" || label == "Category Data") {
                continue; // Skip this variable
            }
            
            // 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);

Please mark correct/helpful if this helps you!