The CreatorCon Call for Content is officially open! Get started here.

Email Script to print a variable if not empty and if a specific cat_item

ubaid1
Giga Contributor

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.

 

1 ACCEPTED SOLUTION

Change below

var Item = current.cat_item;

View solution in original post

6 REPLIES 6

Mike Patel
Tera Sage

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>");
}

 

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

Change below

var Item = current.cat_item;

Thank you so much. I was so close yet so far. Much appreciated, that did the trick.