What are the equivalent variables in email scripts?

Liuduan
Kilo Expert

        What are the equivalent variables in email scripts?

         Fields in sc_request table can be easily accessed from workflow or notification, but how to access them in email scripts?

For example:

In notification: ${sysapproval.description}, ${sysapproval.short_description}

In workflow script: current.description, current.short_description

In email script: ???, ???

         They all correspond to the description or short_description column in the sc_request table. What is the equivalent of them in the email scripts?

1 ACCEPTED SOLUTION

Dear Mr. Harshvardhan,

      Thank you for your help. The following code is working. I can read the sc_request table columns.

      You are great.

      Liuduan

var req = new GlideRecord("sc_request");

req.addQuery('sys_id', current.sysapproval.sys_id);
req.query();

gs.info("test 1: ");    
while(req.next()) {
    gs.info("test 2: " + req.short_description);  
}

View solution in original post

14 REPLIES 14

Harsh Vardhan
Giga Patron

You have to do glide record in emails script to fetch that values. 

 

(function runMailScript(current, template, email, email_action, event) {


   var req = new GlideRecord("sc_request");


   req.addQuery("sys_id", current.request);


   req.query();


   while(req.next()) {


   template.print(req.short_description  + ' ' +req.description);


   }


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

 

Note: I am assuming here your notification is running on sc_req_item table . 

 

For further details refer the below doc link. 

 

https://developer.servicenow.com/app.do#!/lp/new_to_servicenow/app_store_learnv2_automatingapps_newy...

Liuduan
Kilo Expert
Dear Mr. Harshvardhan,
      Thank you for your help.

     I run the email script as part of the email template. In the email template I can access the description field of the sc_request table like this: ${sysapproval.description}. What level is it?

      I run the following code in my mail script, and the while(req.next()){} is not working.

var req = new GlideRecord("sc_request");
req.addQuery("sys_id", current.request);
req.query();
gs.info("test 7.9.3: ");    // This info is showoing
while(req.next()) {
   gs.info("test 7.9.4: " + req.short_description);    // This info is not showing
   }

      Please help me and give me some suggestions. Thank you.

      Duan Liu

req.addQuery("sys_id", current.request);

Could the above line a problem? That is the part that always confuses me.

try now

var req = new GlideRecord("sc_request");
req.addQuery("sys_id", current.sys_id);
req.query();
gs.info("test 7.9.3: ");    // This info is showoing
while(req.next()) {
   gs.info("test 7.9.4: " + req.short_description);    // This info is not showing
   }