Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Fetch dynamic value from decision table

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.

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.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
(function calculatedFieldValue(current) {

var fieldA = current.u_list_items.toString(); // Get value of field 1

if (fieldA != '') { // Check if field value is empty

var individualInformation = fieldA.split(",");
var resultElements = [];
for (var i in individualInformation) {
try {
var inputs = {};
inputs['u_decision_field'] = individualInformation[i];

var dt = new sn_dt.DecisionTableAPI(); // Calling decision table by API call
var response = dt.getDecision('sysid_of_decision_table', inputs);

var result_elements = response.result_elements;
var u_return_value = result_elements.u_decision_result.getValue(); // String
if (resultElements.indexOf(u_return_value) == -1)
resultElements.push(u_return_value);

} catch (e) {
gs.log("Couldn't run this script Error: " + e);
resultElements.push('');
}

}
return resultElements.toString(); // Return end result as string to get stored in field 2

}
})(current);
Loading