0

I am having trouble setting a text value in a custom field I added to the address form.

function fieldChanged_form(type, name) {
    if (name == 'custentity_bsi_agycampus') {

        var lnSeq = nlapiFindLineItemValue('addressbook', 'defaultbilling', 'T');

        if (lnSeq > 0) {
            console.log("selected line " + lnSeq);
            nlapiSelectLineItem('addressbook', lnSeq);
            var agency_campus = nlapiGetFieldText('custentity_bsi_agycampus');
            nlapiSetCurrentLineItemValue('addressbook',
                    'custrecord_bsi_agy_div_bur_sd', agency_campus, true, true);
            console.log('agency' + ',' + agency_campus);
        }

        nlapiCommitLineItem('addressbook');
        console.log('after commit: '
                + nlapiGetCurrentLineItemValue('addressbook',
                        'custrecord_bsi_agy_div_bur_sd'));
    }
}

This script(applied to the Customer Form under the custom code tab) will not set custrecord_bsi_agy_div_bur_sd with the text value from custentity_bsi_agycampus (a custom field in the customer form). However, if I change custrecord_bsi_agy_div_bur_sd to addr1 (a field that is a default in the address form), it works just like I'd like.

This leads me to wonder whether or not I can access my custom field in the address form through 'addressbook' like you can for all of the other address fields. Does anyone know the answer to that question or have an idea of how I can troubleshoot this issue?

Blorgbeard
  • 101,031
  • 48
  • 228
  • 272
Gus
  • 33
  • 4
  • What's the value of the text you're trying to set as the value for custrecord_bsi_agy_div_bur_sd? Is it possible it only accepts numerical data? – TonyH Apr 25 '16 at 22:06
  • custrecord_bsi_agy_div_bur_sd is a free form text field. It will accept strings. – Gus Apr 26 '16 at 21:17

1 Answers1

1

I believe you need to work with addresses as subrecords. Play around with something patterned after this:

// {nlobjSubrecord} Get one of the addresses off the sublist
var subrecord = {};

nlapiSelectLineItem('addressbook', 1);
subrecord = nlapiEditCurrentLineItemSubrecord('addressbook', 'addressbookaddress');

// Set the data on the subrecord
subrecord.setFieldValue('attention', 'Some Guy');
subrecord.setFieldValue('addr1', '1234 5th St');
subrecord.setFieldValue('addr2', 'Apt 234');
subrecord.setFieldValue('addrphone', '5558675309');
subrecord.setFieldValue('city', 'Scottsdale');
subrecord.setFieldValue('state', 'AZ');
subrecord.setFieldValue('country', 'US');
subrecord.setFieldValue('zip', '85260');

// Commit the subrecord to its parent before submitting the parent itself
subrecord.commit();
erictgrubaugh
  • 8,519
  • 1
  • 20
  • 28
  • Yea since 2014.2 I believe you have to do it the way Eric is showing – TMann Apr 25 '16 at 23:17
  • I see something like this in the Help documentation but first you have to load a specific record. I'm trying to make this work on new customers. The record hasn't been created yet and there's no internal id yet. How do I access the addressbook fields on a fresh record like that? The code I pasted above works to copy text into addressbook fields on new customers for fields like companyname and addr1. I can't figure out why it will work on those fields and not my custom fields. – Gus Apr 26 '16 at 21:16
  • The code in this answer should work just fine whether the record is new or existing. You either select an existing addressbook line or a new one, and then edit or create the new address line as appropriate, including setting the values on your custom field. – erictgrubaugh Apr 27 '16 at 03:31