Skip to content

Commit 922fdb8

Browse files
authored
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.
1 parent a674219 commit 922fdb8

File tree

1 file changed

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

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+
(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)