diff --git a/app/models/dialog.rb b/app/models/dialog.rb index e64d057a550..9d6f73119d3 100644 --- a/app/models/dialog.rb +++ b/app/models/dialog.rb @@ -93,7 +93,7 @@ def load_values_into_fields(values, overwrite = true) dialog_field_hash.each_value do |field| field.dialog = self - new_value = values[field.automate_key_name] || values[field.name] + new_value = values[field.automate_key_name] || values[field.name] || values.dig("parameters", field.name) new_value ||= field.value unless overwrite field.value = new_value diff --git a/app/models/resource_action_workflow.rb b/app/models/resource_action_workflow.rb index e56b9e7ff6e..7db6f704d84 100644 --- a/app/models/resource_action_workflow.rb +++ b/app/models/resource_action_workflow.rb @@ -31,7 +31,7 @@ def add_request_to_cart end def update_dialog_field_values(data) - @dialog.load_values_into_fields(data.values.first) + @dialog.load_values_into_fields(data) end def process_request(state) diff --git a/spec/models/dialog_spec.rb b/spec/models/dialog_spec.rb index e770964839b..21df0184fba 100644 --- a/spec/models/dialog_spec.rb +++ b/spec/models/dialog_spec.rb @@ -455,6 +455,25 @@ dialog.load_values_into_fields(vars) expect(dialog_field1.value).to eq("10.8.99.248") end + + it "sets field value when in a hash with a key of 'parameters'" do + vars = {"parameters" => {"field1" => "10.8.99.248"}} + dialog.load_values_into_fields(vars) + expect(dialog_field1.value).to eq("10.8.99.248") + end + + context "with multiple fields" do + let(:dialog_group) { DialogGroup.new(:dialog_fields => [dialog_field1, dialog_field2]) } + let(:dialog_field1) { DialogField.new(:value => "123", :name => "field1") } + let(:dialog_field2) { DialogField.new(:value => "12", :name => "field2") } + + it "sets multiple field values" do + vars = {"field1" => "10.8.99.248", "field2" => "new_value"} + dialog.load_values_into_fields(vars) + expect(dialog_field1.value).to eq("10.8.99.248") + expect(dialog_field2.value).to eq("new_value") + end + end end context "symbol values" do