- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2018 12:16 AM
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);
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2018 01:03 AM
I'm using this if (current.variables.hak_akses == 'true'){. CURRENT. and its working. 😄 Thank you....
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2018 12:28 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2018 12:30 AM
Hi,
Have you tried printing some alert (getMessage()), atleast check whether your variables are getting fetched.
Below are some links, that might help you:
If used in Email Script - Community
Please mark my answer as Correct/Helpful in case that works.
Regards,
Vishrut
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2018 12:45 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎07-06-2018 12:32 AM
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