Displaying Request Item/Catalog Variables Variables in Email Script

Sayantan Dutta1
Tera Contributor

Hi Everyone,

 

We recently have received a requirement wherein we are asked to include the Catalog Item Variables into the Approval Email. I have used the following code which I got form one community post, but it is not populating the details.

 

<mail_script>
    template.print("<b>Summary of Requested items:</b>\n");
    var item = new GlideRecord("sc_req_item");
    item.addQuery("sys_id", current.sysapproval);
    item.query();
    while(item.next()) {
    var nicePrice = item.price.toString();
    if (nicePrice != '') {
        nicePrice = parseFloat(nicePrice);
        nicePrice = nicePrice.toFixed(2);
     }
    template.print("       " + item.cat_item.getDisplayValue() + "\n");
    var keys = new Array();
    var set = new Packages.com.glideapp.servicecatalog.variables.VariablePoolQuestionSet();
    set.setRequestID(item.sys_id);
    set.load();
    var vs = set.getFlatQuestions();
    for (var i=0; i < vs.size(); i++) {
        if(vs.get(i).getLabel() != '' && (vs.get(i).getLabel() != "Order Guide Name") && (vs.get(i).getLabel() != "Requested for") && (vs.get(i).getLabel() != "Approving manager") && (vs.get(i).getLabel() != "Request manager approval") && (vs.get(i).getDisplayValue() != "-- None --")   && (vs.get(i).getDisplayValue() != "") && (vs.get(i).getDisplayValue() != "false")) {
            template.space(4);
    template.print("<b>" + '                 ' +   vs.get(i).getLabel() + " </b> \n" + " <XMP>   \t         " + vs.get(i).getDisplayValue() + "</XMP> \n ");  
            }
        }
    }
</mail_script>

 

I got the following error:

"java.lang.SecurityException: Illegal attempt to access class 'com.glideapp' via script"

 

So, can you help me on how to solve this issue?

 

Regards,

Sayantan

1 ACCEPTED SOLUTION

Ankur Bawiskar
Tera Patron
Tera Patron

@Sayantan Dutta1 

it seems you are in scoped app.

if yes then use this script

    var set = new GlideappVariablePoolQuestionSet();

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

View solution in original post

2 REPLIES 2

Ankur Bawiskar
Tera Patron
Tera Patron

@Sayantan Dutta1 

it seems you are in scoped app.

if yes then use this script

    var set = new GlideappVariablePoolQuestionSet();

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,

 

Yes this change worked. I am marking this as the correct solution.

 

Thank you,

Sayantan