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

i think you need to Verify Delivery Time Field 

Update Business Rule : 

(function executeRule(current, previous /*null when async*/) {

// Ensure the catalog item is available and delivery time is retrieved
if (current.catalog_item) {
var catalogItem = new GlideRecord('sc_cat_item');
if (catalogItem.get(current.catalog_item)) {
var deliveryTime = catalogItem.delivery_time; // Fetch the correct delivery time

if (deliveryTime) {
var dueDateUtils = new DueDateUtils();
var dueDate = dueDateUtils.calculateDueDate(new GlideDateTime(), deliveryTime);

if (dueDate) {
current.due_date = dueDate;
current.update(); // Update the sc_task record
} else {
gs.info('Calculated due date is null');
}
} else {
gs.info('No delivery time found for catalog item');
}
} else {
gs.info('Catalog item record not found');
}
} else {
gs.info('Catalog item is empty');
}
})(current, previous);

 

In Case Business Rule is still not working you could consider using a Scheduled Job to update sc_task records periodically.

 

// Scheduled Job Script
var gr = new GlideRecord('sc_task');
gr.addQuery('due_date', ''); // Find tasks without a due date
gr.query();
while (gr.next()) {
var catalogItem = new GlideRecord('sc_cat_item');
if (catalogItem.get(gr.catalog_item)) {
var deliveryTime = catalogItem.delivery_time;
if (deliveryTime) {
var dueDateUtils = new DueDateUtils();
var dueDate = dueDateUtils.calculateDueDate(new GlideDateTime(), deliveryTime);
if (dueDate) {
gr.due_date = dueDate;
gr.update();
}
}
}
}

Community Alums
Not applicable

You could try creating a sublow in flow designer to pull catalog item details so that it can be reusable across your catalog item flows. The subflow input can be the catalog item name and then you can look up the catalog item record. Once you've found it then you can return it's attributes like delivery time as output to the main flow. The main flow will take this output and you can use it in your catalog tasks that you can drag and drop into the delivery time field