Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
**Use Case:**

When using generic request flows for catalog items, the catalog items have different delivery time. However, flow stages are not flexible enough to dynamically set the due dates based on catalog item's delivery time. This limitation can lead to inaccurate due dates, affecting SLAs and user expectations.

**Proposed Solution:**

To address this, create two business rules to set due dates of RITM and Request:
1. Requested Item (RITM) Due Date:
- Implement a Before Business Rule on the "sc_req_item" table.
- This rule will calculate the due date by adding the delivery time (in days) from the associated catalog item record to the current date.
- The calculated due date will then be set on the RITM.

2. Request Due Date:
- Implement a Before Business Rule on the "sc_request" table.
- It will then determine the maximum (farthest) due date among all RITMs associated with the request and set it as the due date for the request.
- Since RITMs are created before the request record, this logic ensures accurate aggregation of due dates.

**Benefits:**
- Ensures accurate due dates for both RITMs and Requests.
- Improves SLA tracking and reporting.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A BR calculating due date is actually not enhancing SLA tracking. As you are not using SLA's in your code, it has a risk of even conflicting with OOTB SLA functionality

- Enhances user satisfaction by aligning expectations with actual delivery timelines.
- Reduces manual intervention and customization in flows.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/**
* Business Rule: Set due date on Request
* Table: sc_request
* When: before insert
*
* @description
* Sets the "due_date" on a Request by:
* 1) Finding the associated RITM with the highest "due_date".
* 2) Assigning the Request's "due_date" to match that RITM's "due_date".
*/
(function executeRule(current, previous /* null when async */) {

try {
// Query RITMs linked to this Request and pick the one with the highest due_date.
var reqGR = new GlideRecord("sc_req_item");
reqGR.addQuery("request", current.getUniqueValue());
reqGR.orderByDesc('due_date'); // Latest due_date first
reqGR.setLimit(1);
reqGR.query();

if (reqGR.next()) {
// Set due date
current.setValue('due_date', reqGR.getValue('due_date'));
}

} catch (ex) {
var message = ex.getMessage();
gs.error("Business Rule: Error - " + message);
}

})(current, previous);
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/**
* Business Rule: Set due date on RITM
* Table: sc_req_item
* When: before insert
*
* @description
* Sets the "due_date" for a Request Item (RITM) by:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The described process is already available with OOTB SLA's.

* 1) Reading the delivery time (in days) from the associated Catalog Item
* 2) Parsing the days component from the display value (e.g. "5 Days" - 5).
* 3) Adding those days to the record's creation date ("sys_created_on").
* 4) Writing the calculated date to "due_date".
*/
(function executeRule(current, previous /* null when async */) {

try {
// Get days from Catalog Item's delivery time field.
var deliveryTimeDaysStr = current.getDisplayValue('cat_item.delivery_time').split(' ')[0];

// Convert to a Number
var deliveryTimeDays = Number(deliveryTimeDaysStr);

var createdDate = current.getValue('sys_created_on');
var newDueDate = new GlideDateTime(createdDate);

// Add delivery days to created date in UTC to avoid timezone drift.
newDueDate.addDaysUTC(deliveryTimeDays);

// Set due date
current.due_date.setValue(newDueDate.getValue());

// If you also need the estimated delivery date, uncomment the line below:
// current.estimated_delivery.setValue(newDueDate.getValue());

} catch (ex) {
var message = ex.getMessage();
gs.error("Error in BR: Set Due Date on RITM - " + message);
}

})(current, previous);
Loading