can I add if condition on email script?

zulhiyatiuwi
Tera Expert

Hello...

Can i add if condition on email script? i have try it, but it not working. Maybe i do some mistake. I try to add condition based on variables value. i try to create like email script in below. but it is not working. I want to show jenis and otentikasi when value of Terkait hak akses is TRUE. But when I try this simple script. notification always show else condition. Help please.

 

(function runMailScript(current, template, email, email_action, event) {
template.print('<p><font size="4" color="#808080" face="helvetica"><strong>');
template.print(gs.getMessage('Detail ${cat_item} :'));
template.print('</strong></font></p>');

var Terkaithakakses = gs.getMessage('Terkait hak akses');
var Jenis = gs.getMessage('Jenis');
var Otenkasi = gs.getMessage('Otenkasi');
var Informasidurasi = gs.getMessage('Informasi durasi');
var Tanggalmulai = gs.getMessage('Tanggal mulai');
var Tanggalberakhir = gs.getMessage('Tanggal berakhir');

var terkaithakakses = gs.getMessage(': ${variables.hak_akses}');
var jenis = gs.getMessage(': ${variables.jenis}');
var otenkasi = gs.getMessage(': ${variables.otentikasi}');

template.print('<tr>');
template.print('<td><font size="3" color="#808080" face="helvetica">' + Terkaithakakses + '</font></td>');
template.print('<td><font size="3" color="#808080" face="helvetica">' + terkaithakakses + '</font></td>');
template.print('</tr>');
template.print('<tr>');

var ya, tidak;
if (gs.getMessage('${variables.hak_akses}') == 'true'){
ya = gs.getMessage(': Ya');
template.print('<td><font size="3" color="#808080" face="helvetica">' + Terkaithakakses + '</font></td>');
template.print('<td><font size="3" color="#808080" face="helvetica">' + ya + '</font></td>');
template.print('</tr>');
} else {
tidak = gs.getMessage(': Tidak');
template.print('<td><font size="3" color="#808080" face="helvetica">' + Terkaithakakses + '</font></td>');
template.print('<td><font size="3" color="#808080" face="helvetica">' + tidak + '</font></td>');
template.print('</tr>');
}


template.print('</table>');


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

1 ACCEPTED SOLUTION

zulhiyatiuwi
Tera Expert

I'm using this if (current.variables.hak_akses == 'true'){. CURRENT. and its working. 😄 Thank you....

View solution in original post

7 REPLIES 7

Ct111
Giga Sage

Check this example given in wiki for The following is an example script to add users from watch_list as copied recipients.

 

if(!current.watch_list.nil()){
   //get watch list addresses and add to cc
   var watcherIds = current.watch_list.split(",");
 
   //get user records
   var user =new GlideRecord("sys_user");
   user.addQuery("sys_id", watcherIds);
   user.addQuery("notification",2); 
   //email
   user.addQuery("email","!=","");
   user.query();
 
   while(user.next()){
      //add to cc list    
      email.addAddress("cc", user.email, user.getDisplayValue());}}



PLEASE mark my ANSWER as CORRECT if it served your purpose

Shambhu5
Kilo Guru

Hi,

Have you tried printing some alert (getMessage()), atleast check whether your variables are getting fetched. 

Below are some links, that might help you:

Email Script

If used in Email Script - Community

Please mark my answer as Correct/Helpful in case that works.

Regards,
Vishrut
find_real_file.png

This is result of my notification preview

find_real_file.png

Value is TRUE, but in if condition it take else condition.

Kamal17
Kilo Sage

Hi zulhiyatiuwi,

 

Try using the below code (true without quotes),

if(gs.getMessage('${variables.hak_akses}') == true)

 

If its still not working then try printing/logging the value stored in variable 'hak_akses' before you enter the condition part. It might give you a better idea of what is stored inside the variable.

 

Regards,

Udhay