organization_autocomplete.rb 524 B

12345678910111213141516171819
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class FormUpdater::ApplyValue::OrganizationAutocomplete < FormUpdater::ApplyValue::Base
  3. def can_handle_field?(field:, field_attribute:)
  4. field_attribute&.data_option&.[]('relation') == 'Organization'
  5. end
  6. def map_value(field:, config:)
  7. org = Organization.find_by(id: config['value'])
  8. return if !org
  9. result[field][:value] = org.id
  10. result[field][:options] = [{
  11. value: org.id,
  12. label: org.name,
  13. }]
  14. end
  15. end