Anybody know of a workaround to call a client scri...
# suitescript
s
Anybody know of a workaround to call a client script from a before load (view) user event script? Using context.form.clientScriptModulePath, but pageInit doesn’t appear to fire.
b
describe what you are trying to do better
user event scripts run on the server
client scripts run on the client (in this case browser)
s
Using UE submit fields to update the custom record on beforeload event, but changes do not persist to page load, thus, I’m having to manually reload the page. Would be nice to load a client script and run window.location.reload().
b
redirect.toRecord would be more normal
you can also use, clientScriptModulePath, but there are no entrypoints there
not that you would need it to just reload the page
s
Tried that but getting stuck in infinite redirect, I think. 🤔
b
you would just need the code to reload the page
reloading the page wont magically fix an infinite redirect
you need to make your code smart enough not to do that
reloading the page on the client will still trigger the beforeload user event script
s
Excluding client, redirect.ToRecord was creating infinite redirect. I will revisit this approach
Thank you!
j
I've had to deal with the infinite redirect before. Add a parameter to redirect.toRecord and read it in your script, in a way that if that parameter is set, skip the redirect.toRecord.
Copy code
const redirectParams = {
    isReloaded: 'T'
};

const params = scriptContext.request.parameters;

if (params.isReloaded !== 'T') {
    redirect.toRecord({
        type: newRec.type,
        id: newRec.id,
        parameters: redirectParams
    });
}
s
Ahhhhh…thank you, sir! Very much appreciated! Was just going to down a rabbit hole, so perfect timing.