Skip to content

Commit 08cbdc7

Browse files
Fetch dynamic value from decision table (#1920)
* Create Task Creating task when button is clicked with the same details added in Incident ticket. * Fetch dynamic value from decision table If we want to have a scenario like based on "FieldA" of big list of comma separated values, We need to provide its relevant "FieldB" value, Which need not to be repeated again and the key value pair is huge and often changing, In that case we can make use of decision table to fetch key value pair without interrupting any scripts and saving value in "FieldB" which will get changed according to "FieldA" value as it is a calculated field. * README.md Read me file for calculated field using decision builder * Delete UI Actions/Create Task --------- Co-authored-by: Earl Duque <[email protected]>
1 parent 56bf277 commit 08cbdc7

File tree

2 files changed

+36
-0
lines changed
  • Server-Side Components/Server Side/Fetch dynamic value from decision table

2 files changed

+36
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
Fetch dynamic value from decision table
2+
3+
Use case: Map relevant values of field1 to field2 with large list of choices and often changing and needs to be editable by specific admin team.
4+
5+
Solution: If we want to have a scenario like based on "Field1" of big list of comma separated values, We need to provide its relevant "Field2" value, Which need not to be repeated again and the key value pair is huge and often changing, In that case we can make use of decision table to fetch key value pair without interrupting any scripts and saving value in "Field2" which will get changed according to "Field1" value as it is a calculated field.
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
(function calculatedFieldValue(current) {
2+
3+
var fieldA = current.u_list_items.toString(); // Get value of field 1
4+
5+
if (fieldA != '') { // Check if field value is empty
6+
7+
var individualInformation = fieldA.split(",");
8+
var resultElements = [];
9+
for (var i in individualInformation) {
10+
try {
11+
var inputs = {};
12+
inputs['u_decision_field'] = individualInformation[i];
13+
14+
var dt = new sn_dt.DecisionTableAPI(); // Calling decision table by API call
15+
var response = dt.getDecision('sysid_of_decision_table', inputs);
16+
17+
var result_elements = response.result_elements;
18+
var u_return_value = result_elements.u_decision_result.getValue(); // String
19+
if (resultElements.indexOf(u_return_value) == -1)
20+
resultElements.push(u_return_value);
21+
22+
} catch (e) {
23+
gs.log("Couldn't run this script Error: " + e);
24+
resultElements.push('');
25+
}
26+
27+
}
28+
return resultElements.toString(); // Return end result as string to get stored in field 2
29+
30+
}
31+
})(current);

0 commit comments

Comments
 (0)