- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 01:53 AM
Hi @Ankur Bawiskar
We have one requirement we need to send notifications to end user before 8 days to expiry date,I write schedule script to send notifications end user but it is not execute as expected,Please find script below
var endDate = '';
var email = ''; // for email forwarder
var itm = new GlideRecord('sc_req_item');
itm.addQuery('u_revoke_req', true);
itm.addQuery('state', '3');
itm.addQuery('stage', '!=', 'Request Cancelled');
itm.query();
while (itm.next()) {
if (itm.cat_item == '5086e2750f143600cd33c19ce1050e63') {
email = itm.variables.email;
}
if (((itm.cat_item == '0d4419864f9436002fb1e6518110c7b4') && (itm.variables.requesttype != 'Revoke')) || (itm.cat_item == 'cf455a0a4fd436002fb1e6518110c70c') || (itm.cat_item == '1a0898624f5c36002fb1e6518110c717') || (itm.cat_item == '0eb312360fd07600cd33c19ce1050e9e') || (itm.cat_item == 'd6baf467db4ef410298fd4bdd39619f8') || (itm.cat_item == 'f3c485320f907600cd33c19ce1050e88') || ((itm.cat_item == '5086e2750f143600cd33c19ce1050e63') && (email == 'true')) || (itm.cat_item == 'ad14ce7d0fd03600cd33c19ce1050ec3')) {
//endDate = itm.variables.end_date.getDisplayValue();
//gs.log('item name '+itm.cat_item);
if (itm.u_end_date.getDisplayValue()) {
endDate = itm.u_end_date.getDisplayValue();
//gs.log('item name '+ endDate);
}
if (itm.target_date.getDisplayValue()) {
endDate = itm.target_date.getDisplayValue();
//gs.log('item name '+ endDate);
}
var dur = gs.dateDiff(gs.nowDateTime(), endDate, true);
var email = itm.request.requested_for.email;
gs.log('item dur ' + dur);
if (dur <= 691200 || endDate < gs.nowDateTime()) {
gs.log('user notification');
gs.eventQueue("revoke.request", itm, email, itm.number);
}
}
}
thanks
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 10:36 PM
Hi @nag nagesh
Here is the sample script: (Which will send an email notification 31 days before the date.)
var ceTasks = new GlideRecord('sn_hr_core_task');
ceTasks.addEncodedQuery('//add your query');
ceTasks.query();
while (ceTasks.next()) {
var getEffStrDate = ceTasks.work_start_date; //get the date of your selected field
var effStrDate = new GlideDateTime(getEffStrDate);
effStrDate.addDaysLocalTime(-31);
var get60DaysDate = effStrDate.getLocalDate();
var toDateTime = new GlideDateTime();
var toDate = toDateTime.getDate();
var compareDateTime = get60DaysDate.compareTo(toDate); //Comparing both dates
if (compareDateTime == 0) {
gs.eventQueue('sn_hr_core.decison_31_days_global', ceTasks, ceTasks.assigned_to);
}
}
Please mark as helpful/correct if it helps.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-13-2023 10:36 PM
Hi @nag nagesh
Here is the sample script: (Which will send an email notification 31 days before the date.)
var ceTasks = new GlideRecord('sn_hr_core_task');
ceTasks.addEncodedQuery('//add your query');
ceTasks.query();
while (ceTasks.next()) {
var getEffStrDate = ceTasks.work_start_date; //get the date of your selected field
var effStrDate = new GlideDateTime(getEffStrDate);
effStrDate.addDaysLocalTime(-31);
var get60DaysDate = effStrDate.getLocalDate();
var toDateTime = new GlideDateTime();
var toDate = toDateTime.getDate();
var compareDateTime = get60DaysDate.compareTo(toDate); //Comparing both dates
if (compareDateTime == 0) {
gs.eventQueue('sn_hr_core.decison_31_days_global', ceTasks, ceTasks.assigned_to);
}
}
Please mark as helpful/correct if it helps.