unable to print the value from email script to email body

Abdul
Tera Contributor

hi,

 

I am trying to get a value of a variable from a catalog item in an email script and i have to get the last four digits of that number and getting the last four digits of it.

I am sending it to my email body and i am printing it there.

When the email is triggered i am not getting the last 4 digit value.

 

Below are the code:

Email Script:

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

          // Add your code here
          var cardNum = current.variables.card_number_s;
          var lastFour = cardNum.slice(-4);
          template.print(lastFour);
         
})(current, template, email, email_action, event);
 
 
Email Body:
Card Number(s): ${mail_script:Last_four_digits} 
 
Please help thanks 
1 ACCEPTED SOLUTION

Nilesh Pol
Tera Guru

@Abdul 

If you're unsure about how card_number_s is being populated, add some debug logging to verify the value before performing the slice operation: gs.info('Card Number: ' + cardNum);

and If card_number_s is not a string but a number, you will need to convert it to a string before using .slice(). Numbers do not support the .slice() method.

 

Here's how the final email script should be:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var cardNum = String(current.variables.card_number_s);

var lastFour = cardNum.slice(-4);
template.print(lastFour);
})(current, template, email, email_action, event);

View solution in original post

4 REPLIES 4

Rishi_11
Kilo Sage

Hi @Abdul ,

Can you please confirm on which table is your notification running? Also what is the type of the variable card_number_s?

Thanks, 

Rishi.

 

Abdul
Tera Contributor

sys_script_email this is the table i created and i cant see anything on the form saying that this has to run on any particular table

Nilesh Pol
Tera Guru

@Abdul 

If you're unsure about how card_number_s is being populated, add some debug logging to verify the value before performing the slice operation: gs.info('Card Number: ' + cardNum);

and If card_number_s is not a string but a number, you will need to convert it to a string before using .slice(). Numbers do not support the .slice() method.

 

Here's how the final email script should be:

(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var cardNum = String(current.variables.card_number_s);

var lastFour = cardNum.slice(-4);
template.print(lastFour);
})(current, template, email, email_action, event);

Abdul
Tera Contributor

Thank you so much it worked