Hey folks, having some trouble with a Suitescript ...
# suitescript
m
Hey folks, having some trouble with a Suitescript 2.X Client script for viewing the inventory detail subrecord on an assembly build. When I try
currentRecord.getSubrecord({fieldId: 'inventorydetail'})
I get an error saying
org.mozilla.javascript.EcmaError: ReferenceError: \"document\" is not defined. (INVOCATION_WRAPPER#7)
. I do not get this when invoking the Suitescript 1 Client script with the corresponding function
nlapiViewSubrecord("inventorydetail")
. Any ideas on how to resolve this?
a
use 2.1 explicitly that's a Rhino error and 2.1 doesn't use Rhino
alternatively your JSDOC header is funky 😄
(which makes it default to Rhino as fallback)
m
@Anthony OConnor Thanks!
@Anthony OConnor Wait... actually that is not applicable to me I think. This is a client script, which means... wouldn't it not touch Rhino?
a
???
err I see what you're saying, it should be running in the browser and so not using any of the NS JS engines... but maybe some API calls do actually use it still in some kind of way??? idk
m
Hold on, I'm going to physically test it. I think it does involve server side calls in some manner... so gotta test it.
👍 1
a
i mean that's 100% a Rhino error, so it is managing to throw an error it must be part of what's happening 😄
m
@Anthony OConnor I'm sure you're right... but yeah... 2.1 isn't making the error change. Might need to report it to Netsuite.
a
post your JS doc header
m
@Anthony OConnor Sorry about the late reply. Here you go (actually decided to post the full script)
Copy code
/**
 * @NApiVersion 2.1
 * @NScriptType ClientScript
 * @NAmdConfig /SuiteScripts/ScriptsConfig.json
 *
 * TODO
 *
 */

define(  [] ,
function () {

    return {
        pageInit: function(context)
        {
            var currentRecord = context.currentRecord;

            console.log(currentRecord.getSubrecord({fieldId: 'inventorydetail'}))
        }
    }

});
This script IS added to the document by another script, but it's also a 2.1 script with the same header. Also, I can get the same error by just running things in the console.
a
huh wild... idk then is this just something not supported in 2.1 then????
sorry man i thought I for sure know what this issue was, I was wrong
m
@Anthony OConnor Don't be sorry, you were a great help. And yeah... this is one of two things I think that I've noticed that 2.1 doesn't do, the other being have an equivalent to nlapiSetLineItemValue (rather than nlapiSetCurrentLineItemValue) for editing line items that aren't selected. I'm probably gonna have to find some alternative for some scripts here at some point if they are pushing everyone to 2.1 😛
b
looks like you found a rare instance where a client side script is running serverside, usually you only see that for address subrecords. From what you described so far, its probably the suitescript 1 client script deployed on the inventory detail. You can check by undeploying the suitescript 1 client script on the inventory detail or modifying it so its pageInit function returns early if document is undefined
m
@battk Holy moly that did it. If you don't mind me asking, how did you find this out? Did you experience it before with addresses or something?
a
there was ANOTHER unrelated SS1.0 client script on the record? and that was actually throwing the error? but you were assuming it was your new 2.1 script because that's what was new and what you messing with??? so you never mentioned an SS1.0 client script, so battk just inferred it?
impressive work
b
My development account has a suitescript 2 script client script deployed to all records that just logs when entry points are triggered. The example code provided didnt cause any issues. so i did the same thing with a suitescript 1 script to reproduce the issue. I already knew that client script can run serverside, especially on subrecords. So there was already an expectation on my side that there was a script deployed on the inventory detail, which is the only other subrecord mentioned in the question
👍 2
technically i was lazy and only actually implemented logging for the suitescript 1 page init entry point, again since i knew from experience that the pageInit was the client side entry point that is triggered serverside
m
@battk That is sweet! Thanks so much for discovering this! Yeah... I just would have not thought this was the issue, to be frank. So thank you so much!
@Anthony OConnor There was such a script, but I didn't think it effected things since it was never an issue with the Suitescript 1 client scripts running on the Assembly Build. Which I am now regretting 😛. To be frank... I haven't touched that script in like... 4 to 5 years. Guess it's time to change it! It's a really funky script that blocks certain buttons and field on the Inventory Detail that aren't really blockable via regular Netsuite methods... so yeah... it touches document. :o
👍 1