Leave date greater than 5 days and asset not returned in workflow will trigger a task in RITM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-30-2024 01:42 AM - edited 07-30-2024 05:37 AM
Hi,
I am trying to implement a script in the if activity in the workflow to trigger a task based on the yes condition.
1- There are multiple dynamic tasks in WF which is triggering for different assets assigned to the offboarded user. We have a customized choice field " Assets Returned " with Yes/No values in all the tasks.
2- There is a variable "Leave date" in the item . The scenario is if Leave date is greater than 5days and if Asset returned is "NO", then it should trigger a task to a group.
I have implemented the below code and it is not working . Please let me know where to modify this.
(function() {
var leaveDate = new GlideDateTime(current.variables.leave_date);
gs.log('Leave Date: ' + leaveDate);
// Get the current date and time
var currentDate = new GlideDateTime();
gs.log('Current Date: ' + currentDate);
// Create a GlideDateTime object for the date 5 days from now
var date5DaysLater = new GlideDateTime();
date5DaysLater.addDaysUTC(5); // I have taken 1day for testing purpose
// Calculate the number of days between the leave date and current date
var daysDifference = (leaveDate.getNumericValue() - currentDate.getNumericValue()) / (1000 * 60 * 60 * 24);
gs.log('Days Difference: ' + daysDifference);
// Fetch the value of field from catalog task
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id);
taskGR.addQuery('short_description' ,'CONTAINS', "Offboarding - Local IT");
taskGR.query();
var assetreturned = '';
if (taskGR.next()) {
assetreturned = taskGR.getValue('u_assets_returned');
gs.log('Asset: ' + assetreturned);
}
// Check if the leave date is greater than 5 days from now and field X is "No"
if (daysDifference > 5 && assetreturned == 'No') {
return 'yes';
} else {
return 'no';
}
})();
Please let me know if anybody can help in this.
Thanks in Advance.