Skip to content

Commit 4ae02a1

Browse files
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".
1 parent e393bae commit 4ae02a1

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/**
2+
* Business Rule: Set due date on Request
3+
* Table: sc_request
4+
* When: before insert
5+
*
6+
* @description
7+
* Sets the "due_date" on a Request by:
8+
* 1) Finding the associated RITM with the highest "due_date".
9+
* 2) Assigning the Request's "due_date" to match that RITM's "due_date".
10+
*/
11+
(function executeRule(current, previous /* null when async */) {
12+
13+
try {
14+
// Query RITMs linked to this Request and pick the one with the highest due_date.
15+
var reqGR = new GlideRecord("sc_req_item");
16+
reqGR.addQuery("request", current.getUniqueValue());
17+
reqGR.orderByDesc('due_date'); // Latest due_date first
18+
reqGR.setLimit(1);
19+
reqGR.query();
20+
21+
if (reqGR.next()) {
22+
// Set due date
23+
current.setValue('due_date', reqGR.getValue('due_date'));
24+
}
25+
26+
} catch (ex) {
27+
var message = ex.getMessage();
28+
gs.error("Business Rule: Error - " + message);
29+
}
30+
31+
})(current, previous);

0 commit comments

Comments
 (0)