Trying to update the contacts address if it is the...
# suitescript
n
Trying to update the contacts address if it is the default billing address but this doesn't seem to be working or setting anything
var loadContact = record.load({
                    
type: record.Type.CONTACT,
                      
id: scriptContext.request.parameters.contactid,
                    
isDynamic: true,
                
});
                    
var currentAddressCount = loadContact.getLineCount({
                        
'sublistId': 'addressbook'
                    
});
                    
for (var i = 0; i < currentAddressCount.length; i++) {
                        
loadContact.selectLine({
                            
sublistId: 'addressbook',
                            
line: i
                        
});
                        
var defaultbilling = loadContact.getCurrentSublistValue({
                            
sublistId : 'addressbook',
                            
fieldId: 'defaultbilling'
                        
});
                        
if (defaultbilling == true) {
                            
var addressSubrecord = loadContact.getCurrentSublistSubrecord({
                                
sublistId: 'addressbook',
                                
fieldId: 'addressbookaddress'
                            
});
                            
addressSubrecord.setValue({
                                
fieldId: 'addr1',
                                
value: scriptContext.request.parameters.address
                            
});
                        
}
                        
loadContact.commitLine({
                            
sublistId: 'addressbook'
                        
});
                    
}
                
var recordId = loadContact.save({
                    
enableSourcing: true,
                    
ignoreMandatoryFields: true
                
});
s
Copy code
const contact = new Contact(scriptContext.request.parameters.contactid)
const addrline  =_.find(contact.addressbook, addr => addr.defaultbilling === true)
addrline.addressbookaddress.addr1 = scriptContext.request.parameters.address
contact.save()
n
@stalbert not sure what your answer means
s
sorry, I was going to write out how I'd code that for reference
n
Ah got ya. Is there anything wrong with the way I did it? Just trying to figure out why my way didn't work
s
maybe try coding it in
standard
mode rather than
dynamic
mode? I tend to only use dynamic mode if I have to.