0

I'm unable to convert array of string to integer. I'm getting the following error undefined method map for "[\"118\", \"119\"]":String.

Any idea how to resolve this?

            def job_template_by_id
              job_template_id = var_search(@handle.object, 'job_template_id') ||
                                var_search(@handle.object, 'dialog_job_template_id')
                               
              job_template_id = job_template_id.map(&:to_i)

              @handle.vmdb(SCRIPT_CLASS).where(:id => job_template_id) if job_template_id
            end

Error:

[----] E, [2022-07-07T16:08:09.928258 #534:2afb827cdb68] ERROR -- automation: Q-task_id([r837_miq_provision_2172]) <AEMethod launch_ansible_job> The following error occurred during method evaluation:
[----] E, [2022-07-07T16:08:09.930286 #534:2afb827cdb68] ERROR -- automation: Q-task_id([r837_miq_provision_2172]) <AEMethod launch_ansible_job>   NoMethodError: undefined method `map' for "[\"118\", \"119\"]":String
[----] E, [2022-07-07T16:08:09.931630 #534:2afb827cdb68] ERROR -- automation: Q-task_id([r837_miq_provision_2172]) <AEMethod launch_ansible_job>   /ManageIQ_Custom/AutomationManagement/AnsibleTower/Operations/StateMachines/Job/launch_ansible_job:113:in `job_template_by_id'
1
  • The error message tells you everything: It says that var_search returns a String. Commented Jul 8, 2022 at 7:22

1 Answer 1

2

Well, that error says that it's not an array which you expect, it's a string, probably JSON. so you need to parse it firstly

job_template_id = JSON.parse(job_template_id).map(&:to_i)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.