-
Notifications
You must be signed in to change notification settings - Fork 908
Set Due Date on Request and RITM based on Delivery Time #1893
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
AnandMahajan2799
wants to merge
3
commits into
ServiceNowDevProgram:main
from
AnandMahajan2799:anand-new-snippet_02
Closed
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...usiness Rules/Set Due Date on Request and RITM based on Delivery Time/README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
| - Enhances user satisfaction by aligning expectations with actual delivery timelines. | ||
| - Reduces manual intervention and customization in flows. | ||
31 changes: 31 additions & 0 deletions
31
... Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_request.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); |
39 changes: 39 additions & 0 deletions
39
...ess Rules/Set Due Date on Request and RITM based on Delivery Time/set_due_date_on_ritm.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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: | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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