- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 06:25 AM
Hello All,
We have to use the due date from the description of the RITM to set the RITM due date. Use that same due date (-2 weeks) for each of the tasks on that RITM.
I have created one BR for this but it's not working , please let me knowif I'm doing it wrong.
Any help would be appreciated .Thank you!
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 03:39 AM
Try bellow updated script:
(function executeRule(current, previous /*null when async*/) {
if (!current.description) {
gs.info("Description is empty.");
return;
}
// Extract the due date from the description
var string = current.description;
gs.info("Description: " + string); // Log the description for debugging
var dueDateMatch = string.match(/Due Date:\s*(\d{1,2}-\d{1,2}-\d{4})/); // Updated regex for DD-MM-YYYY format
if (dueDateMatch && dueDateMatch[1]) {
var dateStr = dueDateMatch[1]; // Get the matched date string
gs.info("Matched Due Date: " + dateStr); // Log the matched date
// Split the date string into day, month, year
var dayMonthYear = dateStr.split("-");
// Create a GlideDateTime object
var gDate = new GlideDateTime();
gDate.setValue(dayMonthYear[2].trim() + "-" + dayMonthYear[1].trim() + "-" + dayMonthYear[0].trim() + " 12:00:00"); // Adjust order for GlideDateTime
// Set the due date only if it's valid
if (gDate) {
current.due_date = gDate;
gs.info("Due date set to: " + gDate); // Log the due date set
// Now set the same due date for each associated sc_task
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id); // Assuming 'request_item' is the field linking tasks to RITM
taskGR.query();
while (taskGR.next()) {
// Set the due date for the task
taskGR.due_date = gDate;
taskGR.update(); // Don't forget to update the record
gs.info("Due date set for task " + taskGR.number + ": " + gDate);
}
} else {
gs.info("Invalid date conversion.");
}
} else {
gs.info("No valid due date found in description.");
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-01-2024 07:10 AM
hi @C_S3
Looks your due date format is 10-10-2024; try bellow updated script once:
(function executeRule(current, previous /*null when async*/) {
// Ensure the description is not empty
if (!current.description) {
gs.info("Description is empty.");
return;
}
// Extract the due date from the description
var string = current.description;
gs.info("Description: " + string); // Log the description for debugging
var dueDateMatch = string.match(/Due Date:\s*(\d{1,2}-\d{1,2}-\d{4})/); // Updated regex for DD-MM-YYYY format
if (dueDateMatch && dueDateMatch[1]) {
var dateStr = dueDateMatch[1]; // Get the matched date string
gs.info("Matched Due Date: " + dateStr); // Log the matched date
// Split the date string into day, month, year
var dayMonthYear = dateStr.split("-");
// Create a GlideDateTime object
var gDate = new GlideDateTime();
gDate.setValue(dayMonthYear[2].trim() + "-" + dayMonthYear[1].trim() + "-" + dayMonthYear[0].trim() + " 12:00:00"); // Adjust order for GlideDateTime
// Set the due date only if it's valid
if (gDate) {
current.due_date = gDate;
gs.info("Due date set to: " + gDate); // Log the due date set
} else {
gs.info("Invalid date conversion.");
}
} else {
gs.info("No valid due date found in description.");
}
})(current, previous);
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 12:57 AM
Hello @Rajesh Chopade1 ,
It is working for RITM, but for sc_task the due date is not visible until we closed complete the state.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-07-2024 03:39 AM
Try bellow updated script:
(function executeRule(current, previous /*null when async*/) {
if (!current.description) {
gs.info("Description is empty.");
return;
}
// Extract the due date from the description
var string = current.description;
gs.info("Description: " + string); // Log the description for debugging
var dueDateMatch = string.match(/Due Date:\s*(\d{1,2}-\d{1,2}-\d{4})/); // Updated regex for DD-MM-YYYY format
if (dueDateMatch && dueDateMatch[1]) {
var dateStr = dueDateMatch[1]; // Get the matched date string
gs.info("Matched Due Date: " + dateStr); // Log the matched date
// Split the date string into day, month, year
var dayMonthYear = dateStr.split("-");
// Create a GlideDateTime object
var gDate = new GlideDateTime();
gDate.setValue(dayMonthYear[2].trim() + "-" + dayMonthYear[1].trim() + "-" + dayMonthYear[0].trim() + " 12:00:00"); // Adjust order for GlideDateTime
// Set the due date only if it's valid
if (gDate) {
current.due_date = gDate;
gs.info("Due date set to: " + gDate); // Log the due date set
// Now set the same due date for each associated sc_task
var taskGR = new GlideRecord('sc_task');
taskGR.addQuery('request_item', current.sys_id); // Assuming 'request_item' is the field linking tasks to RITM
taskGR.query();
while (taskGR.next()) {
// Set the due date for the task
taskGR.due_date = gDate;
taskGR.update(); // Don't forget to update the record
gs.info("Due date set for task " + taskGR.number + ": " + gDate);
}
} else {
gs.info("Invalid date conversion.");
}
} else {
gs.info("No valid due date found in description.");
}
})(current, previous);