On an invoice, how can i get the bill to address i...
# suitescript
n
On an invoice, how can i get the bill to address id and search on the invoice customer for the matching address id so i can get some information on the customer record by address?
b
addresses have 2 fields with the unfortunate id
internal id
The
address internal id
is what is shown in the ui on the customer in the id column, and is what is used as a select value in the
billaddresslist
field
it is unfortunately not the actual internal id of the address subrecord
the
internal id
is the actual internal id used for normal things like searching by internal id, or loading the address subrecord
n
@battk Yeah, that is my struggle haha. I can't seem to find a way to link them
b
its the id in the url when you view the addres subrecords
you can get the internal id by getting the
billingaddress
subrecord and getting its id field
from search, its on the billing address join in the internal id column
n
@battk I have no problem getting the id's from the customer addressbook suberecord. I am just trying to figure out how I match it to the bill to on the invoice
b
do you have the internal id or the address internal id
you will predictably have a 50% chance of getting the right answer if you are guessing
n
For example, the id I am able to get from the invoice record is 22924 but the id on the customer record is 13396
b
is 22924 the internal id or the address internal id?
n
that is the billingaddressid
Only id I am able to get from the invoice
for the bill to
b
lets be clear, there are 2 valid answers
internal id, or address internal id
they are different things, and billingaddressid is not an answer
there are multiple ways to get the different ids, i listed some in my answers earlier
n
var invoiceSearchObj = search.create({
type: "invoice",
filters:
[
["type","anyof","CustInvc"],
"AND",
["internalid","anyof","782532"],
"AND",
["mainline","is","T"]
],
columns:
[
search.createColumn({
name: "internalid",
join: "CUSTBODY_KES_BILLTO",
label: "Internal ID"
}),
search.createColumn({name: "custbody_kes_billto", label: "Bill To"}),
search.createColumn({
name: "addressinternalid",
join: "CUSTBODY_KES_BILLTO",
label: "Address Internal ID"
}),
search.createColumn({
name: "internalid",
join: "billingAddress",
label: "Internal ID"
})
]
});
var searchResultCount = invoiceSearchObj.runPaged().count;
log.debug("invoiceSearchObj result count",searchResultCount);
invoiceSearchObj.run().each(function(result){
// .run().each has a limit of 4,000 results
return true;
});
This is the search I just ran to test for the specific invoice i am on. And the last search column is the only thing that returned a value and that value is 292944, which doesn't match the id on the customer address subrecord of 13396
b
it shouldnt
if you are referring to the id column of the addressbook on the customer
as i said before, thats the address internal id
search.createColumn({
name: "internalid",
join: "billingAddress",
label: "Internal ID"
})
is the internal id
n
Right, i get that now. But is there any way to get a value that would match to one of the address subrecords on the customer?
b
you would have to compare to the internal id of the address on the customer
addressinternalid
is only a valid column on an entity search
if you are loading the record, you would get the address subrecrd and get its id field to get the internal id
for the customer, the address internal id is on the addressbook sublist
the internal id is on the address book address subrecord
n
var invCust = record.load({'type': 'customer', 'id': cust, 'isDynamic': false});
                        
var addrSublist = 'addressbook';
                        
var linecount = invCust.getLineCount({'sublistId':addrSublist});
                        
var invDelivery = false;
                        
var coverLetter = false;
                        
var invEmail = '';
                        
for(var line = 0; line < linecount; line++)
                        
{
                            
var defaultBilling = invCust.getSublistValue({'sublistId': addrSublist, 'fieldId':'defaultbilling', 'line': line});
                            
if (defaultBilling == true) {
                                
var addressSubrecord = invCust.getSublistSubrecord({
                                    
sublistId: addrSublist,
                                    
fieldId: 'addressbookaddress',
                                    
line: line
                                    
});
                                    
// Set all required values here.
                                    
invDelivery = addressSubrecord.getValue({fieldId: 'custrecord_kes_cfaexcelinvoicedelivery'});
                                    
coverLetter = addressSubrecord.getValue({fieldId: 'custrecord_kes_coverletterreqd'});
                                    
invEmail = addressSubrecord.getValue({fieldId: 'custrecord_kes_invoiceemail'});
                            
}
                        
}
So I load the customer record and then in the address subrecord I was before logging the address internalid. However, it is returning 13396 where as my invoice address search is returning 292944
b
dont know what you are logging
but keep in mind, the value from your transaction search is the internal id
the internal id is found on the address subrecord
n
okay, i'll keep trying. Thanks
b
specifically in the id field