Welcome to Community Week 2025! Join us to learn, connect, and be recognized as we celebrate the spirit of Community and the power of AI. Get the details  

Email Notification that Account is getting expired

NiKhil70
Kilo Guru

Hi ,

I have a Requirement to send an email Notification to the Requester  when the end date of Contractor is getting close .

In detail :

In On-boarding REQUEST form , we have ( Start date & end date ).

If the Employee type is Contractor then we should enter the End date which is Mandatory .

I have entered  (start date = Jan 1 , 2019 )& (End Date is June 30 , 2019) while submitting an on boarding Request for user "XYZ"

Requester should get Email Notification that user ( "XYZ") account is coming up for expiration on May 30 , June 15 ( Nothing but 30 days & 15 Days before Expiration )

How can i achieve this ?

Require Inputs to proceed further .

 

Thanks

NR.

1 ACCEPTED SOLUTION

Hi Naveen ,

Thanks for providing inputs , i made some changes to your script and Added some functions , its working correct .

PLease find the Below Code :

 

var newexp=gs.dateGenerate(SS.variables.End_date,'00:00:00'); // End_date is variable name

var gdt= new GlideDateTime(newexp);

var sjb= gs.dateGenerate(gs.now(),'00:00:00');

var gdt1= new GlideDateTime(sjb);

gdt1.addDays(30);

if(gdt.getDate().toString()==gdt1.getDate().toString())

{

//gs.log("RITM NUMBER IS " +SS.number);

                gs.eventQueue('Alert check',SS,gs.getUser(),SS.variables.ob_hire_report_to);

gs.log("end count of RITM is " +SS.number);       

}

}

}

THanks

NR

View solution in original post

11 REPLIES 11

I Tried the below script in scheduled job but not working .

 

var ED = new GlideRecord('sc_req_item');
ED.query();
while(ED.next())
{
var exp = new GlideDateTime(ED.variables.ob_contctrs_voul_interns_end_date).getDate();
if(exp.addDaysUTC(-3)==new GlideDateTime().getDate())
{
gs.eventQueue('Alert check',ED,gs.getUser());
}
}

 

Thanks

NR

Could you please check what logs you are getting

 

var ED = new GlideRecord('sc_req_item');
ED.query(); //add the item name filter, so that it will take less time to run the query
while(ED.next())
{

gs.log('Inters end date', ED.variables.ob_contctrs_voul_interns_end_date);


var exp = new GlideDateTime(ED.variables.ob_contctrs_voul_interns_end_date).getDate();
if(exp.addDaysUTC(-3)==new GlideDateTime().getDate())
{
gs.eventQueue('Alert check',ED,gs.getUser());
}
}

 

Hi shashi ,

I can see noting in script logs after running my script .

The Variable type is DATE (ob_contctrs_voul_interns_end_date) .

Thanks

NR

Naveen63
Tera Contributor

Hi NR,

 

For your requirement:

Step 1:Create Schedule job which calculate difference between current server date/time and your end date.

 

var gr = new GlideRecord('table_name');

var datediff = gs.dateDiff('your field name', gs.nowDateTime(), true);  // true return value will be formatted in number of seconds

var dateformat = datediff/86400;

if(dateformat < 5){

 

gs.eventqueue('event name', gr);

}

 

Step 2: register event

Step 3: create notification without condition.

 

Please mark it correct and also helpful.

 

Regards,

Naveen

Hi Naveen ,

Thanks for providing inputs , i made some changes to your script and Added some functions , its working correct .

PLease find the Below Code :

 

var newexp=gs.dateGenerate(SS.variables.End_date,'00:00:00'); // End_date is variable name

var gdt= new GlideDateTime(newexp);

var sjb= gs.dateGenerate(gs.now(),'00:00:00');

var gdt1= new GlideDateTime(sjb);

gdt1.addDays(30);

if(gdt.getDate().toString()==gdt1.getDate().toString())

{

//gs.log("RITM NUMBER IS " +SS.number);

                gs.eventQueue('Alert check',SS,gs.getUser(),SS.variables.ob_hire_report_to);

gs.log("end count of RITM is " +SS.number);       

}

}

}

THanks

NR