Hello. When we create a new address in Suitelet we...
# suitescript
b
Hello. When we create a new address in Suitelet we use this code.
Copy code
const createShipAddress = (customerId, addressObj) => {
            let rec = record.load({
                type: record.Type.CUSTOMER,
                id: customerId,
                isDynamic: true
            });

            rec.selectNewLine({
                sublistId: 'addressbook'
            });
    
            // Set an optional field on the sublist line.
            rec.setCurrentSublistValue({
                sublistId: 'addressbook',
                fieldId: 'label',
                value: addressObj.addressName
            });
    
            // Create an address subrecord for the line.
            var subrec = rec.getCurrentSublistSubrecord({
                sublistId: 'addressbook',
                fieldId: 'addressbookaddress'
            });
    
            subrec.setValue({
                fieldId: 'country',
                value: addressObj.country
            });

            subrec.setValue({
                fieldId: 'addressee',
                value: addressObj.addressee
            });
    
            subrec.setValue({
                fieldId: 'city',
                value: addressObj.city
            });
    
            subrec.setValue({
                fieldId: 'state',
                value: addressObj.state
            });
    
            subrec.setValue({
                fieldId: 'zip',
                value: addressObj.zip 
            });
    
            // Save the sublist line.
            rec.commitLine({
                sublistId: 'addressbook'
            });
    
            // Save the record.
            try{
                var recId = rec.save();
    
                log.debug({
                    title: 'Record created successfully',
                    details: 'Id: ' + recId
                });
            } catch (e){
                log.error({
                    title: e.name,
                    details: e.message
                });
            }       
        }
However, could I know how to get the ID address of created address please? Do I need to create a customer Saved Search for address subrecord?
b
yes
b
@battk I created an address, get that value and set it in SO.
soRec.setValue('shipaddresslist', addressId);
However, the SO Ship To Select is Custom, even the SHIP To shows the correct address information. Could I know how to set that SHIP TO SELECT value to the just created address please?
b
are you sure you got the correct id
the address list uses the addressbook line's id
not the id of the addres subrecord
b
Oh I remember that now. Could you tell me how to get that please? I think I tried SuiteQL before
Last time when I tried it was very difficult as I couldn't use lookup or search as it always return that internal id of address
b
start easy first
get the id from the customer record
and hardcode it to see if it fixes the problem
then figure out how to do the search or query