I've encountered an issue when converting a script...
# suitescript
m
I've encountered an issue when converting a script's version from 2.0 to 2.1 (and with no other changes beyond version) where
record.attach
to attach a file to a sales order does not actually attach the file to the transaction. the function gets evaluated, log lines immediately before and after indicate no error is encountered. including incorrect variables, syntax, or format yields the expected error. ultimately, the file just does not attach. changing back to 2.0 works fine. i've also recreated a series of scripts and libraries which perform the same core functions in an attempt to reproduce, but cannot reproduce the behavior (2.1 attaches files fine in the rebuild - whether the file id and record id are hardcoded or not). anyone else encountered something similar? i'm crafting a support case now.
s
you're saying it works in 2.1 when you use your library, but not when the same code is in your script itself?
m
in my bundled solution, record.attach doesn't work at all when the script is changed to 2.1. the rest of the script fires fine, as well as no errors being produced and logging around the record.attach function indicates nothing out of the ordinary
i'll post legitimate detail here in a sec
• User Event Script renders button on Sales Order ◦ On click: request sent to Suitelet, banner message indicating action status is displayed • Suitelet generates a JSON file --> attaches the file to the sales order --> sends response to be displayed in banner message
2.0 works without issue. snippet inc
modules___applicable_function.js
i removed all the file create content & unnecessary stuff for the sake of debugging. here are the results, which is what i find odd:
^ 2.1. with solely changing the Suitelet's version to 2.0, it'll succeed and attach the file just fine:
what i can't figure out is why specifically it stops working in this script. in attempts to debug, i've created much more simplified versions of each current script strictly to test libraries containing n/record and performing the same record.attach task, but they work. that's where i'm struggling - it's clearly something to do with these specific scripts since it's not a global issue, but it doesn't make sense as to why record.attach is the only thing not working when changing the version from 2.0 to 2.1 and it doesn't throw an error (short of providing incorrect parameters in record.attach)
hoping someone else has come across this and knows what the deal is
e
I have observed very strange behaviors when trying to change script versions. I nearly always end up making entirely new scripts instead.
m
exciting, thanks lol
going to spin up some copies and hopefully confirm the issue goes away before my netsuite support case comes up
i highly doubt anyone is invested in my problem, but @erictgrubaugh you might find this interesting
i've identified the cause and am finally opening a support ticket now that i've identified it
👀 1
running this from the suitelet's deployment hyperlink:
here are the results: • when i comment out line 12: it works • when i change the version from 2.1 to 2.0: it works • when the version is 2.1 and line 12 is not commented out: it does not attach the file
also confirmed: • issue isn't limited to loading the same record i'm attaching the file to. the behavior is consistent even when i load a different transaction record, but attach to my 31252 sales order. • issue isn't due to having the record currently loaded and not saved. the behavior is consistent even if the record is saved prior to attaching the file
e
Interesting and frustrating. Hope you get a resolution from support
fingers crossed 1
m
seems like a defect. not yet acknowledged as a defect by netsuite. however, the only workaround discovered is if record.load is present anywhere within the chain of events, record.save must also be present. record.attach will only succeed if it's called somewhere between record.load and record.save, but not outside either.
examples: does not work:
Copy code
var transactionRecord = record.load({type: 'salesorder', id: 31252});
record.attach({record: {type: 'file', id: 58865}, to: {type: 'salesorder', id: 31252}});
does not work:
Copy code
var transactionRecord = record.load({type: 'salesorder', id: 31252});
transactionRecord.save()
record.attach({record: {type: 'file', id: 58865}, to: {type: 'salesorder', id: 31252}});
works:
Copy code
var transactionRecord = record.load({type: 'salesorder', id: 31252});
record.attach({record: {type: 'file', id: 58865}, to: {type: 'salesorder', id: 31252}});
transactionRecord.save()
the weirdest part is it's not like normal record edit behavior, because this rule applies even if my record.attach call is attaching two records which are entirely unrelated to the record i loaded and plan to save
¯\_(ツ)_/¯
hope this helps someone else.
e
That's wild. Thanks for sticking with it and for following up here.
m
@mbrewer Have you tried this and defining specifically if the record loaded was in dynamic mode or not? I've seen some people report that specifically setting values that should be defaulted has made a big difference in behavior/performance at times. Just a curiosity
m
@Matt Carter yep - that was the NetSuite Support contact's first recommendation as well. the same behavior is exhibited both dynamic & not
right now, i have a workaround but won't be implementing the change until there's confirmation this 2.1 behavior is intended and not a defect. netsuite is reviewing fingers crossed
Defect #765393. U5
🙌 1
finally confirmation & closure 🙃