title: How to get the fields of an address from a location record using SuiteScript
body: <p>Context: A RESTlet written in SuiteScript v1, but I'll use v2 if I must.</p>
  
  <p><strong>Important: Solution must work serverside.</strong></p>
  
  <p>The location record has a field titled Main Address. The field id is mainaddress_text.</p>
  
  <p>When I edit the Main Address field using the NetSuite website it presents me with the normal address editing form with the normal address fields, so it appears that NetSuite stores the address like it does the addresses on, for example, the customer record, in fields called Country, Attention, Addressee, Phone etc.</p>
  
  <p>I want to get the values of these fields, but I can't work out how.</p>
  
  <p>I have loaded the location using</p>
  
  <pre><code>location = nlapiLoadRecord('location', locationid)
  </code></pre>
  
  <p>The schema browser (<a href="https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/schema/record/location.html" rel="nofollow noreferrer">https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/schema/record/location.html</a>) suggests there is a field called mainAddress of type Address.</p>
  
  <p>I have attempted to access the mainAddress field using statements like these:</p>
  
  <pre><code>location.getField('mainaddress') //returns null
  location.getSubList('mainaddress') //returns null
  location.getLineItemCount('mainaddress') //returns -1
  location.getFieldValue('mainaddress') //returns null
  location.getFieldText('mainaddress') //returns null
  </code></pre>
  
  <p>But no success.</p>
  
  <p>I also tried <code>location.getLineItemCount('addressbook')</code> in case there was a field named like in the customer record but that returned -1.</p>
  
  <p>The records browser (<a href="https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/location.html" rel="nofollow noreferrer">https://system.netsuite.com/help/helpcenter/en_US/srbrowser/Browser2016_1/script/record/location.html</a>) suggests there is a field called addrtext of type Address.</p>
  
  <p>I have attempted to access the addrtext field using statements like these:</p>
  
  <pre><code>location.getField('addrtext') //returns null
  location.getSubList('addrtext') //returns null
  location.getLineItemCount('addrtext') //returns -1
  location.getFieldValue('addrtext') //returns null
  location.getFieldText('addrtext') //returns null
  </code></pre>
  
  <p>But no success.</p>
  
  <p>The records browser also describes fields called addr1, addr2, addr3, addressee, attention, city and so on.</p>
  
  <p>I have attempted to access those fields using statements like these:</p>
  
  <pre><code>location.getFieldValue('attention') //returns null
  location.getFieldValue('addressee') //returns null
  location.getFieldValue('addr1') //returns null
  location.getFieldValue('addr2') //returns null
  location.getFieldValue('addr3') //returns null
  location.getFieldValue('city') //returns null
  location.getFieldValue('state') //returns null
  location.getFieldValue('country') //returns null
  </code></pre>
  
  <p>But no success.</p>
  
  <p>The only way I've found to get the address data is using <code>location.getFieldValue('mainaddress_text')</code> but that returns the address as one string with the parts of the address delimited by <code>&lt;br&gt;</code>-tokens.</p>
  
  <p>How can I get the individual address fields?</p>