Method: Jamf::Extendable#set_ext_attr

Defined in:
lib/jamf/api/classic/api_objects/extendable.rb

#set_ext_attr(ea_name, value, validate_popup_choice: true, refresh: false) ⇒ void

This method returns an undefined value.

Set the value of an extension attribute

The new value is validated based on the data type of the Ext. Attrib:

  • If the ext. attrib. is defined with a data type of Integer/Number, the value must be an Integer.

  • If defined with a data type of Date, the value will be parsed as a timestamp, and parsing may raise an exception. Dates can’t be blank.

  • If defined wth data type of String, ‘to_s` will be called on the value.

By default, the full EA definition object is fetched to see if the EA’s input type is ‘popup menu’, and if so, the new value must be one of the defined popup choices, or blank.

The EA definitions used for popup validation are cached, so we don’t have to reach out to the server every time. If you expect the definition to have changed since it was cached, provide a truthy value to the refresh: parameter

To bypass popup validation complepletely, provide a falsey value to the validate_popup_choice: parameter. WARNING: beware that your value is the correct type and format, or you might get errors when saving back to the API.

Note that while the Jamf Pro Web interface does not allow editing the values of Extension Attributes populated by Scripts or LDAP, the API does allow it. Bear in mind however that those values will be reset again at the next recon.

Parameters:

  • name (String)

    the name of the extension attribute to set

  • value (String, Time, Integer)

    the new value for the extension attribute for this user

  • validate_popup_choice (Boolean) (defaults to: true)

    validate the new value against the E.A. definition. Defaults to true.

  • refresh (Boolean) (defaults to: false)

    Re-read the ext. attrib definition from the API, for popup validation.

Raises:

  • (ArgumentError)


164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/jamf/api/classic/api_objects/extendable.rb', line 164

def set_ext_attr(ea_name, value, validate_popup_choice: true, refresh: false)
  raise ArgumentError, "Unknown Extension Attribute Name: '#{ea_name}'" unless ea_types.key? ea_name

  value = validate_ea_value(ea_name, value, validate_popup_choice, refresh)

  # update this ea hash in the @extension_attributes array
  ea_hash = @extension_attributes.find { |ea| ea[:name] == ea_name }

  raise Jamf::NoSuchItemError, "#{self.class} '#{name}'(id #{id}) does not know about ExtAttr '#{ea_name}'. Please re-fetch and try again." unless ea_hash

  ea_hash[:value] = value

  # update the shortcut hash too
  @ext_attrs[ea_name] = value if @ext_attrs
  @changed_eas << ea_name
  @need_to_update = true
end