Anyone ever have an issue loading custom field val...
# suitescript
k
Anyone ever have an issue loading custom field values off an address record? I've a script that works just fine - but the second my address record has a custom field filled out - it stops being searchable via my script - like NetSuite has transformed it into another record type in the background.
s
are you accessing the address as a subrecord?
k
No
I'm just doing
nlapiLookupField ('address',addressToReference,'address1');
though, I'm thinking I need to use the address book record type instead - but I can't quite get it to cooperate
or. I can do the simple thing and do a customer search instead.
duh kevin
s
probably shouldn't be doing
nlapi*
anything these days 🙂 However, keep in mind that NS is pushing us to use address records so I've been trying to ignore any leftover fields that look like mirrored address data elsewhere on a record.
and custom address fields do seem to work just like custom fields on any other record type in my experience.
if you paste more of the script I may be able to provide you an alternative
k
well, I'm transitioning to using a search - which has the right values in it just gotta figure out how to set the field values from the search
This is what I was doing:
Copy code
function FieldChanged(type, name)
{
   if ((name === 'custrecord_po_record_address_book'))
   {
	 var fieldsToLookup = new Array();
	 var addressToReference = nlapiGetFieldValue('custrecord_po_record_address_book');
	 var deviceAddress1 = nlapiLookupField ('address',addressToReference,'address1');
	 var deviceAddress2 = nlapiLookupField ('address',addressToReference,'address2');
	 var deviceCity = nlapiLookupField('address',addressToReference,'city');
	 var deviceState = nlapiLookupField('address',addressToReference,'state');
	 var deviceZip = nlapiLookupField('address',addressToReference,'zip');
	 var deviceCustStorNum = nlapiLookupField('address',addressToReference,'custrecord_po_store');
	 var deviceAltStorNum = nlapiLookupField('address',addressToReference,'custrecord_alternate_store');
	 var deviceBuildingID = nlapiLookupField('address',addressToReference,'custrecord_building_id');
	   nlapiSetFieldValue('custrecord_po_record_address_line_1',deviceAddress1);
	   nlapiSetFieldValue('custrecord_po_record_address_line_2',deviceAddress2);
	   nlapiSetFieldValue('custrecord_po_record_city',deviceCity);
	   nlapiSetFieldValue('custrecord_po_record_state',deviceState);
	   nlapiSetFieldValue('custrecord_po_record_zip',deviceZip);
	   nlapiSetFieldValue('custrecord_po_record_cust_store_number',deviceCustStorNum);
	   nlapiSetFieldValue('custrecord_po_device_alt_store_id',deviceAltStorNum);
	   nlapiSetFieldValue('custrecord_po_record_building_id',deviceBuildingID);
   }
}
This is where I am on revision
Copy code
function FieldChanged(type, name)
{
   //  Prompt for additional information,  based on values already selected.
   if ((name === 'custrecord_po_record_address_book'))
   {
	 var addressToReference = nlapiGetFieldValue('custrecord_po_record_address_book');
	 
	 var customerSearch = nlapiSearchRecord("customer",null,
[
   ["address.internalidnumber","equalto",addressToReference]
], 
[
   new nlobjSearchColumn("address1","Address",null), 
   new nlobjSearchColumn("address2","Address",null), 
   new nlobjSearchColumn("city","Address",null), 
   new nlobjSearchColumn("state","Address",null), 
   new nlobjSearchColumn("zipcode","Address",null)
   new nlobjSearchColumn("custrecord_po_store","Address",null), 
   new nlobjSearchColumn("custrecord_alternate_store","Address",null), 
   new nlobjSearchColumn("custrecord_building_id","Address",null), 
]
);
so search runs - now I just gotta figure out how to do my field values according to the search results.
s
I'd translate that to something like this
Copy code
const rec = new TheCustomRecord(context.currentRecord)
const address = new Address(id)
rec.custrecord_po_record_cust_store_number = address.custrecord_po_store
// and so on
if I'm understanding it correctly, the whole thing would be about 10 lines of code.
k
found a developer to help me the rest of the way - and yeah it's a blistering 10 lines of code