Skip to content

Commit 523c74c

Browse files
Flow action get value from choice known error workaround (ServiceNowDevProgram#832)
1 parent 46a37c9 commit 523c74c

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Get choice field value (mitigating known error)
2+
3+
This Flow Action serves as a solution for addressing a recognized problem within Flow Designer ([known error](https://support.servicenow.com/kb?id=kb_article_view&sysparm_article=KB0813846)). The issue involves copying of a choice field from one record to another through the drag-and-drop functionality of the data pill. In this scenario, the copied choice field's label is incorrectly set instead of the actual underlying value. Consequently, this leads to the emergence of the "missing choice value" error, indicated by the choice value appearing in blue, disrupting subsequent logic that relies on this field.
4+
To resolve this issue, I have written a simple generic Flow Designer Action “Get choice field label and value”. This action provides a reusable and effective workaround for addressing the problem in any instance where copying a choice field is required.
5+
6+
## Instruction
7+
8+
Create a Flow Action with the following inputs and outputs:
9+
- inputs: table, record_id, choice_field_name
10+
- outputs: choice_value, choice_label
11+
12+
In your Flow you can then access the choice_value via the data pill and drag and drop it to set the choice value of another record. If the display value is needed as well, it can also be accessed via the choice_label output.
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
(function execute(inputs, outputs) {
2+
var table = inputs.table;
3+
var recordId = inputs.record_id;
4+
var choiceFieldName = inputs.choice_field_name;
5+
6+
try {
7+
var gr = new GlideRecord(table);
8+
gr.addQuery("sys_id", recordId);
9+
gr.query();
10+
11+
if (gr.next()) {
12+
outputs.choice_value = gr.getValue(choiceFieldName);
13+
outputs.choice_label = gr.getDisplayValue(choiceFieldName);
14+
} else {
15+
// Handle the case where the record with the specified ID is not found.
16+
gs.error("Record not found with sys_id: " + recordId);
17+
}
18+
} catch (ex) {
19+
// Handle any exceptions that may occur during the script execution.
20+
gs.error("An error occurred: " + ex);
21+
}
22+
})(inputs, outputs);

0 commit comments

Comments
 (0)