From e393bae440f150cd1ab1a2d4ef82c25a20f91658 Mon Sep 17 00:00:00 2001 From: AnandMahajan2799 <99655598+AnandMahajan2799@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:04:36 +0530 Subject: [PATCH 1/4] Create Set due date on RITM Sets the "due_date" for a Request Item (RITM) based on delivery time set on catalog item record. Follows the below step to calculate and set value: 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". --- .../set_due_date_on_ritm.js | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_ritm.js diff --git a/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_ritm.js b/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_ritm.js new file mode 100644 index 0000000000..234107e8a6 --- /dev/null +++ b/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_ritm.js @@ -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: + * 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); From 4ae02a162321e4fbfcdd79fe9897b26ecd17642b Mon Sep 17 00:00:00 2001 From: AnandMahajan2799 <99655598+AnandMahajan2799@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:08:58 +0530 Subject: [PATCH 2/4] Create Set due date on Request Sets the "due_date" on a Request with associated RITM with the highest "due_date". Follows the below steps to calculate and set the field: 1) Finding the associated RITM with the highest "due_date". 2) Assigning the Request's "due_date" to match that RITM's "due_date". --- .../set_due_date_on_request.js | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_request.js diff --git a/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_request.js b/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_request.js new file mode 100644 index 0000000000..0ac968dbaf --- /dev/null +++ b/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_request.js @@ -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); From ea6d63d95b314d778550a6983bfdfe6330583f18 Mon Sep 17 00:00:00 2001 From: AnandMahajan2799 <99655598+AnandMahajan2799@users.noreply.github.com> Date: Tue, 7 Oct 2025 13:13:32 +0530 Subject: [PATCH 3/4] Create README.md CreateD README file --- .../README.md | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/README.md diff --git a/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/README.md b/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/README.md new file mode 100644 index 0000000000..37f9e85e55 --- /dev/null +++ b/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/README.md @@ -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. +- Enhances user satisfaction by aligning expectations with actual delivery timelines. +- Reduces manual intervention and customization in flows. From cee03c8f473c571c437d97e13b2f7b0526e853fc Mon Sep 17 00:00:00 2001 From: AnandMahajan2799 <99655598+AnandMahajan2799@users.noreply.github.com> Date: Tue, 7 Oct 2025 15:00:43 +0530 Subject: [PATCH 4/4] Update README.md Removed benefits related to SLA which was creating confusion --- .../README.md | 1 - 1 file changed, 1 deletion(-) diff --git a/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/README.md b/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/README.md index 37f9e85e55..ed640ed743 100644 --- a/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/README.md +++ b/Server-Side Components/Business Rules/Set Due Date on Request and RITM based on Delivery Time/README.md @@ -17,6 +17,5 @@ To address this, create two business rules to set due dates of RITM and Request: **Benefits:** - Ensures accurate due dates for both RITMs and Requests. -- Improves SLA tracking and reporting. - Enhances user satisfaction by aligning expectations with actual delivery timelines. - Reduces manual intervention and customization in flows.