can't seem to find this answer googling. I have a ...
# suitescript
r
can't seem to find this answer googling. I have a sublist of type
LIST
that is being created via code (adding sublist, columns, and data in a
beforeLoad
function. Within
beforeLoad()
, I can populate the sublist by using
.setSublistValue()
How can I manually rebuild the data from a Client Script? tried both
N/currentRecord.selectLine()
&
.setSublistValue()
& getting an
SSS_INVALID_SUBLIST_OPERATION CurrentRecord.selectLine
.
e
Per the Help, you cannot add lines to a
LIST
r
saw that as well. Still get the same error with type
EDITOR
, but that introduces a different issue since people shouldn't be able to edit the list directly.
the goal is just to have a sublist show custom information, then be able to refresh that sublist manually when desired.
b
what does the code in the user event and client script look like
r
https://pastebin.com/kNdSMAY4 has both user event & client script
b
wrong place to do the refreshing
you cant do it clientside with any of the list type sublists
at least not if the number of lines can change
the refresh button will trigger another beforeLoad user event where you can add the sublist to the form again
r
tried that, but hitting it didn't do anything. It looks like it's only designed to be used when a custom sublist is being powered by a saved search? which this isn't since I have to populate it manually, since I can't find a way to have a saved search yield different results based on record edit mode (
CREATE
vs
EDIT
). I thought maybe I could customize the function that the refresh button does, but didn't see any way to do that either.
b
put better logs in your user event script beforeLoad
pay attention to them when you press the refresh button
r
do you know how to log when the refresh button is hit and have it hit the Execution log in NetSUite?
b
the logs go to the user event script that added the button
well, the refresh button triggers a beforeload of your user event sciprt, which will have its own logs
r
that was what I was trying to ask
so the if hitting "refresh" triggers a beforeload, which event script is it triggering. The records?
blue button is what's added with the native
.addRefreshButtion()
. Hitting it triggers an XHR request to
https://<tenant>.<http://app.netsuite.com/app/accounting/transactions/salesord.nl?nexus=1&warnne[…]custpage_uv_fq_sublist_freight_quotes&ts=1737606094626|app.netsuite.com/app/accounting/transactions/salesord.nl?nexus=1&warnne[…]custpage_uv_fq_sublist_freight_quotes&ts=1737606094626>
. so.. looks like it would be the same user event attached to the transaction? And response looks like an HTML that is the form with a bunch of additional javascript scripts attached in html
so looks like it's calling the sales order transaction again, which I can attach to the
beforeLoad
of it. But I'm lost as to how to divert requests on a sublist refresh away from the normal transaction
beforeLoad
that would trigger when just opening the record normally
that would seem to solve my issues if I could do that
b
there is no diverting
they go to the same place
if for some reason you need to tell the difference between an edit, refresh, or new record, then you need to add logic that looks at the
scriptContext.request
r
sorry, misspoke. not divert which url is loaded. I can see it's hitting ultimately the same url. With a normal transaction load, the url is •
<tenant>.<http://app.netsuite.com/app/accounting/transactions/salesord.nl?id=267972&whence=&e=T|app.netsuite.com/app/accounting/transactions/salesord.nl?id=267972&whence=&e=T>
. and it returns the complete html of the entire transaction. When hitting the refresh button, the url is •
<tenant>.<http://app.netsuite.com/app/accounting/transactions/salesord.nl?nexus=1&warnnexuschange=F&at=T&cf=174&includecsc=T&id=267972&r=T&e=T&id=267972&machine=custpage_uv_fq_sublist_freight_quotes&ts=1737606094626|app.netsuite.com/app/accounting/transactions/salesord.nl?nexus=1&warnnexuschange=F&at=T&cf=174&includecsc=T&id=267972&r=T&e=T&id=267972&machine=custpage_uv_fq_sublist_freight_quotes&ts=1737606094626>
which returns only the html of the sublist. So, what I'm trying and failing at asking is, if both requests are hitting the same
beforeLoad()
, within the transactions attached User Event, do you know what check I can make within there to only run the code would return the sublist with updated data. None of the
context.UserEventTypes
seem to match against a sublist refresh
b
pick whichever url query parameter you think best matches
i usually use the r and machine parameters
r
machine
at least does have the id I specified as the sublist ID, so that would be a good start. Thank you.
now to figure out what code to write that will return the updated form sublist results
@battk I appreciate the suggestions. Took some time to experiment today to experiment and found some interesting takes. While the "refresh" button sends an XHR request to the server, which is handled by the same User Event as the original transaction itself, it's only returning just the HTML specific to the custom sublist. However, if I try to intercept the request the following inside the
beforeLoad
of the transaction
Copy code
if (scriptContext.request.parameters.hasOwnProperty('machine')) {
            let sublistRefreshID = scriptContext.request.parameters['machine'];
            let freightQuoteSublist = scriptContext.form.getSublist({
                id: uvFQLibID.sublist.FREIGHT_QUOTES.id,
            });
            freightQuoteSublist.setSublistValue({
                id: uvFQLibID.sublist.FREIGHT_QUOTES.field.ID,
                line: 0,
                value: Math.random() + 'manual',
            });
        }

        uvFQLib.generateFreightQuoteSublist(scriptContext);
then I get an error that
freightQuoteSublist
is undefined, which means the sublist doesn't exist yet (the
uvFQLib.generateFreightQuoteSublist()
is what has the
.addSublist()
function in it. Only thing I can think of is that when the refresh button is it, the request to the server is basically an entire record load, complete with all events & triggers, on NetSuite's end, then NetSuite intercepts the response as a final hop, and strips out all the HTML except for the sublist, and then only returns that. This runs completely opposite to how I normally handle XHR requests, which is to only do/process what the XHR request is for and provide just that, not do the entire work again, and then remove what you don't need. I guess I'll have to chalk this up to another NetSuite quirk.
b
you need to recreate the form all over again
that includes your custom sublist
r
yea, that's what I wasn't expecting. I was looking for a "just XHR the changed data", not recreate everything a second time. Lesson Learned.