lib/jss/api_object/extension_attribute.rb
# Get an Array of Hashes for all inventory objects
# with a desired result in their latest report for this EA.
#
# Each Hash is one inventory object (computer, mobile device, user), with these keys:
#   :id - the computer id
#   :name - the computer name
#   :value - the matching ext attr value for the objects latest report.
#
# This is done by creating a temprary {AdvancedSearch} for objects with matching
# values in the EA field, then getting the #search_results hash from it.
#
# The AdvancedSearch is then deleted.
#
# @param search_type[String] how are we comparing the stored value with the desired value.
# must be a member of JSS::Criterion::SEARCH_TYPES
#
# @param desired_value[String] the value to compare with the stored value to determine a match.
#
# @return [Array<Hash{:id=>Integer,:name=>String,:value=>String,Integer,Time}>] the items that match the result.
#
Get an Array of Hashes for all inventory objects
with a desired result in their latest report for this EA.

Each Hash is one inventory object (computer, mobile device, user), with these keys:
:id - the computer id
:name - the computer name
:value - the matching ext attr value for the objects latest report.

This is done by creating a temprary {AdvancedSearch} for objects with matching
values in the EA field, then getting the #search_results hash from it.

The AdvancedSearch is then deleted.
Get an Array of Hashes for all inventory objects with a desired result in their latest report for this EA . Each Hash is one inventory object ( computer mobile device user ) with these keys : : id - the computer id : name - the computer name : value - the matching ext attr value for the objects latest report . This is done by creating a temprary { AdvancedSearch } for objects with matching values in the EA field then getting the #search_results hash from it . The AdvancedSearch is then deleted .
def all_with_result(search_type, desired_value)
      raise JSS::NoSuchItemError, "EA Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY}." unless @in_jss
      unless JSS::Criteriable::Criterion::SEARCH_TYPES.include? search_type.to_s
        raise JSS::InvalidDataError, 'Invalid search_type, see JSS::Criteriable::Criterion::SEARCH_TYPES'
      end
      begin
        search_class = self.class::TARGET_CLASS::SEARCH_CLASS
        acs = search_class.make api: @api, name: "ruby-jss-EA-result-search-#{Time.now.to_jss_epoch}"
        acs.display_fields = [@name]
        crit_list = [JSS::Criteriable::Criterion.new(and_or: 'and', name: @name, search_type: search_type.to_s, value: desired_value)]
        acs.criteria = JSS::Criteriable::Criteria.new crit_list
        acs.create :get_results
        results = []
        acs.search_results.each do |i|
          value =
            case @data_type
            when 'Date' then JSS.parse_datetime i[@symbolized_name]
            when 'Integer' then i[@symbolized_name].to_i
            else i[@symbolized_name]
            end 
          results << { id: i[:id], name: i[:name], value: value }
        end 
      ensure
        acs.delete if acs.is_a? self.class::TARGET_CLASS::SEARCH_CLASS
      end
      results
    end
def all_with_result ( search_type , desired_value ) raise JSS :: NoSuchItemError , "EA Not In JSS! Use #create to create this #{self.class::RSRC_OBJECT_KEY}." unless @in_jss unless JSS :: Criteriable :: Criterion :: SEARCH_TYPES . include? search_type . to_s raise JSS :: InvalidDataError , 'Invalid search_type, see JSS::Criteriable::Criterion::SEARCH_TYPES' end begin search_class = self . class :: TARGET_CLASS :: SEARCH_CLASS acs = search_class . make api : @api , name : "ruby-jss-EA-result-search-#{Time.now.to_jss_epoch}" acs . display_fields = [ @name ] crit_list = [ JSS :: Criteriable :: Criterion . new ( and_or : 'and' , name : @name , search_type : search_type . to_s , value : desired_value ) ] acs . criteria = JSS :: Criteriable :: Criteria . new crit_list acs . create :get_results results = [ ] acs . search_results . each do | i | value = case @data_type when 'Date' then JSS . parse_datetime i [ @symbolized_name ] when 'Integer' then i [ @symbolized_name ] . to_i else i [ @symbolized_name ] end results << { id : i [ :id ] , name : i [ :name ] , value : value } end ensure acs . delete if acs . is_a? self . class :: TARGET_CLASS :: SEARCH_CLASS end results end
Get an Array of Hashes for all inventory objects
with a desired result in their latest report for this EA.
Get an Array of Hashes for all inventory objects with a desired result in their latest report for this EA .
# case # each
the items that match the result.
the items that match the result .
Array<Hash{:id=>Integer,:name=>String,:value=>String,Integer,Time}>
search_type
None
desired_value
the value to compare with the stored value to determine a match.
the value to compare with the stored value to determine a match .