Populate due date on sc task

dvelloriy
Kilo Sage

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.

 

6 REPLIES 6

Community Alums
Not applicable

Adding Delivery Time to Catalog Items > Creating a Script Include > Setting Due Date via Business Rule > Using GlideBusinessCalendar 

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?

Community Alums
Not applicable

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.

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.