A regular client script seems to only be available...
# suitescript
o
A regular client script seems to only be available in edit mode
j
That is correct. You will need to use a user event script instead.
o
right, but a UE is server side, so I can't work with the DOM
gonna try a WFA script, but i think that's server side too?
or might have to use a button
j
Yeah, buttons I have seen done. I'm looking through my scripts to see if I did anything like this without but don't see anything yet.
j
user event script
Copy code
function beforeLoad(ctx) {
  if (ctx.type !== ctx.UserEventType.VIEW {
    return;
  }
  ctx.form.clientScriptModulePath = '/path/to/your/clientscript';
}
🧙‍♂️ 1
💯 1
the client script will run in view mode
m
The example shows a button, but in reality it just attaches a client script to the record
this is equivelant to the 'form level' script you can add when you create a custom form
I think there is also a limitation though... I believe only 1 of such scripts can be attached to a form at a time (even using the example on Stack Overflow). Could be wrong though.
If you have any questions, message me. The function that will matter to you is form.setScript()
o
thanks @Michael Pope yeah i got it working with setScript and a self executing function that checks for context (only executes in a client side context)
m
Sweet!
Glad you got it working
o
thanks for the ninja mode answer @jkabot you found that pathway by looking at the page source?