Method: IntacctRB::Contact#get_by_name

Defined in:
lib/intacctrb/contact.rb

#get_by_name(options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/intacctrb/contact.rb', line 15

def get_by_name(options = {})
  # return false unless object.intacct_id.present?

  options[:fields] = [
    :contactid,
    :contactname
  ] if options[:fields].nil?

  response = send_xml('get') do |xml|
    xml.function(controlid: "f4") {
      xml.readByName {
        xml.object 'contact'
        xml.keys object.try(:name) || options[:name]
        xml.fields '*'
      }
    }
  end

  if successful?
    data = OpenStruct.new({
      id: response.at("//contact/RECORDNO").try(:content),
      name: response.at("//contact/CONTACTNAME").try(:content)
    })
  end

  return_result(response, data)
end