- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎05-31-2018 08:27 AM
Hi All,
Would really appreciate some help on this, probably very simple to those that know how.
Context:
I have a variable set that is auto populated by a 3rd party. the variable set is generic so has 2 different date fields.
Start_Date and End_Date, now both of these values are always populated. However the starter item is triggered when the new starter starts, and the leaver item is triggered when the End Date changes.
Both trigger the same notification.
This is an example and I have many more date fields on my use case, so I cant simply create a unique notification for each scenario. What I want to do is create a Mail script that I can add to my generic notification.
--------
I want the mail script to:
1. print the Start date if not empty and when the catalog item is for new starter
else
2. print the end date if field is not empty and when the catalog item is for a leaver
else
3. print nothing
The mail script that I have written so far gives me the date value correctly if the date variable is not empty but I am not sure how to do the rest..
-----------
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var Startdate = current.variables.EmployeeStartDate;
if (current.variables.EmployeeStartDate != '');
{
template.print("<p>Employee Start Date: </li>" + current.variables.EmployeeStartDate + "</p>");
}
})(current, template, email, email_action, event);
Thanks in advance.
Solved! Go to Solution.
- Labels:
-
Scripting and Coding

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 09:59 AM

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-04-2018 08:31 PM
When you use if condition you don't need ; at the end so remove that and it should work.
Something like
if (current.variables.EmployeeStartDate != ''){
template.print("<p>Employee Start Date: </li>" + current.variables.EmployeeStartDate + "</p>");
}else if (current.variables.EmployeeEndDate != ''){
template.print("<p>Employee End Date: </li>" + current.variables.EmployeeEndDate + "</p>");
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 09:52 AM
Thanks mike;
but thats not what i am trying to do.
I am trying to check if it is a specific cat item, and if the field is populated then do this.
Else check if it is another cat item of interest and if field is empty, then print this.. but i cant get it to work.
(function runMailScript(/* GlideRecord */ current, /* TemplatePrinter */ template,
/* Optional EmailOutbound */ email, /* Optional GlideRecord */ email_action,
/* Optional GlideRecord */ event) {
var Item = current.sys_id;
var Startdate = current.variables.EmployeeStartDate;
var Enddate = current.variables.EmployeeEndDate;
//var Terminationdate = current.variables.TerminationDate;
if(Item == "cc7888e637419b4020a0532e53990e73" && Startdate != "")
{
template.print("<p>Employee Start Date: </li>" + Startdate + "</p>");
}
else if (Item == "fbc8446a37419b4020a0532e53990eb6" && Enddate != "")
{
template.print("<p>Employee End Date: </li>" + Enddate + "</p>");
}
})(current, template, email, email_action, event);
I think my conditions are not working. Not sure why

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 09:59 AM
Change below
var Item = current.cat_item;
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
‎06-06-2018 05:46 PM
Thank you so much. I was so close yet so far. Much appreciated, that did the trick.