Using NSDAL from NetSuite Fasttrack Toolkit, when ...
# suitescript
w
Using NSDAL from NetSuite Fasttrack Toolkit, when I load a sales order, I can pull the 'billaddress' field, but the line breaks (<br>) are stripped out. How can I get the field data with the line breaks intact?
t
billaddress1, billaddress2, billaddresstown, etc
(check the id's, doing it from memory)
n
Cannot speak to NFT but if you use <record>.getSubrecord you will have the address record object and can access the various fields directly as mentioned by @Tristan Day At which point you can format the data as you wish if you need to add in <br>.
w
If a custom billing or shipping address is used, there is no record in the address subrecord that corresponds to the address on the transaction, so you cannot get the discrete fields.
n
@Shawn Talbert might be the man to answer this as the resident NFT expert.
s
@wes_w This isn't a NFT question, just plain NS. Try using the
billingaddress
or
shippingaddress
fields on the SalesOrder object. There is a billing address on the base type, so that typically means someone has used it successfully in the past. https://exploreconsulting.github.io/netsuite-fasttrack-toolkit-ss2/classes/DataAccess_SalesOrderBase.SalesOrderBase.html#billingaddress
I don't recall which record type it was - apparently not sales order but I recall some transaction did not have billing and/or shipping address subrecords available to script for some unknown reason. Looks like SalesOrder wasn't it so the appropriate way to access that is via the subrecord - which in NFT is simply property access as I mention above.
I do not recommend using body level billaddress1, etc. as they are deprecated as far as I know, replaced by the subrecord approach.
w
@Shawn Talbert This is a case where the addresses are not saved to the address subrecord. They are custom addresses and only appear on the sales order record. Using native suitescript, the field has <br> for line breaks. Using NSDAL, the breaks are stripped out. I need the data with the line breaks.
n
@Shawn Talbert apologies he did say "Using NSDAL from NetSuite Fasttrack Toolkit" wasn't to know his issue was not specific to or related to how he was using NFT
s
my answer remains the same Wes.
n
@wes_w what makes you think the address is not saved? When are you accessing the SO?
s
If you have a custom billing address it should appear on the field I mention above. Please confirm that.
w
the billing address object is pretty much empty, and the billaddress string has the line breaks stripped out
n
Have you tried
transction.getSubrecord({fieldId: 'billingaddress'});
w
no. I'll try that
This is what I'm expecting from billaddress (with line breaks)
This has \n instead of <br>, but I'm good with that
n
I'd avoid that like the plague, stick to getting the subrecord except in advanced PDFs. NS loads the record behind the scene and jacks it in to the field on the fly as I recall digging around the browser console.
w
OK, so I am loading the sales order in a Suitelet using context parameters to grab the record Id like so:
Copy code
let recordId = context.request.parameters.id;
let transaction = new SalesOrder(recordId);
let billingAddressSubRecord = transaction.getSubrecord({fieldId: 'billingaddress'});
I get a type error: transaction.getSubrecord is not a function What is the method to pull the subrecord when the record is loaded that way using NSDAL?
n
getSubrecord is native suitescript you'd use on the NS record object. You're not using the native object it seems. If you'd done record.load you'd have the correct object to use that method on.
I don't know what NSDAL is 🤷‍♂️
s
SalesOrder.billingaddress
should be populated methinks, if it is a custom address on that transaction
by the way, if you ever need to reach into the native NS record, it's available as
nsrecord
on the SalesOrder (or any other NSDAL object for that matter).
the
billingaddress
is the subrecord; just much simpler javascript to access it.
I just confirmed this works, for a custom billing address on a Sales Order in a netsuite account. In a suitelet:
const so = new SalesOrder(13110) ctx.response.write(JSON.stringify(so.billingaddress, null, 2))
results in
Copy code
{
  "id": null,
  "_id": null,
  "addr1": "Test Custom addr 1",
  "addr2": "custom addr2",
  "addr3": "",
  "addressee": "Test",
  "addrphone": "6505551212",
  "addrtext": "Test\r\nTest Custom addr 1\r\ncustom addr2\r\nSome Custom City CA 94403\r\nUnited States",
  "attention": "",
  "city": "Some Custom City",
  "country": "US",
  "state": "CA",
  "zip": "94403",
  "override": false
}
and those values match what I entered into the -Custom- address on the SO in the user interface. @wes_w sounds like you have some other issue going on.
🤷‍♂️
w
ok. good to know that I can use nsrecord to get some things differently. Some of our orders are imported from a third party procurement platform, so that may be causing some weirdness in the addresses. I think I can work around it with the nsrecord.
s
no need to workaround it, but do what you want. 🙂