Populate due date on sc task
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 11:33 AM
Hi All,
We have a requirement to populate due date on sc_task using the delivery time updated on catalog items.
So, we have few catalog items related to finance like accounts Payable where delivery time is 2-3 business days and few generic ones like ask a question where delivery time is 5-6 business days.
Can someone recommend on a best approach to do this? I know we can write a business rule on sc task table to populate this but is it a right approach since the size of sc task, ritm table will grow over time and BR might bring performance issues eventually.
We have flows associated to each of these catalog items. Can we introduce something the create task activity of the flow to populate due date from cat item? if yes, can someone please guide me through?
Thanks for your support.

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-08-2024 12:16 PM
Adding Delivery Time to Catalog Items > Creating a Script Include > Setting Due Date via Business Rule > Using GlideBusinessCalendar
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 06:36 AM
Hi Tushar, Thanks for sharing this. i would appreciate if you could please share the code for script include and business rule if you have it handy?

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 07:17 AM
Create a Script Include for Due Date Calculation :
var DueDateUtils = Class.create();
DueDateUtils.prototype = {
initialize: function() {},
// Method to calculate the due date based on the delivery time
calculateDueDate: function(startDate, deliveryTime) {
if (!startDate || !deliveryTime) return null;
var calendar = new GlideBusinessCalendar();
var dueDate = calendar.addBusinessDays(startDate, deliveryTime);
return dueDate;
},
type: 'DueDateUtils'
};
Create a Business Rule to Set Due Date on sc_task:
After Insert > Condition: current.catalog_item.isNotEmpty();
(function executeRule(current, previous /*null when async*/) {
// Ensure the catalog item and delivery time are available
if (current.catalog_item) {
var deliveryTime = current.catalog_item.u_delivery_time;
if (deliveryTime) {
var dueDateUtils = new DueDateUtils();
var dueDate = dueDateUtils.calculateDueDate(new GlideDateTime(), deliveryTime);
if (dueDate) {
current.due_date = dueDate;
current.update();
}
}
}
})(current, previous);
If my answer helped you in any way, please then mark it as helpful or correct.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-09-2024 10:16 AM
Thanks Tushar however this is not working.
One thing which i changed in the BR is u_delivery_time. I changed it to delivery_time as its not a custom field.
Raised a request, sc task is generated however the due date is still empty.
Please advise.