In a Client Script, can you trigger code when the ...
# suitescript
n
In a Client Script, can you trigger code when the record is deleted?
c
What are you actually wanting to achieve? I can guess at wanting to notify a user in 1 session if another user deletes the record they are viewing?
n
@CD actually i have parameters in the url from a record I came from. On delete, I want to go back to the record I came from
m
@Nicholas Williams You can do that in
afterSubmit
on a UE script, which is what I'd recommend using for this. Even if you could do it in a client script, it would likely trigger the redirect before the delete went through, much like returning
false
in
saveRecord
.
n
yeah, but i need to get url parameters before delete & redirect. Can't do that in userevent. @MTNathan
m
@Nicholas Williams You should be able to get url parameters using
context.request.parameters.[paramterName]
(assuming this is SS2.x), though my only uses of that that I can find quickly are in
beforeLoad
so I don't know if it'll work directly in
afterSubmit
. If it doesn't work in
afterSubmit
, you could always just add a scripted field in
beforeLoad
to store the parameter info in, and then reference it in the
afterSubmit
.
After checking the docs,
context.request
appears to only be available in
beforeLoad
, but you could still leverage that in combination with a scripted field.
n
that is what I though but got this in beforeLoad: TypeError: Cannot read property 'parameters' of null [at Object.beforeLoad (/SuiteApps/com.suitecoders.afm/userevent/SC - AFM - Folder Configuration.js3329)]
also, @MTNathan this is 2.1
m
Huh, that's odd - what's your code look like? I'm still using SS2.0 (I'm behind the times, I know) but I can't imagine that would make a difference for something that basic. Absolute worst-case, you could add a field in
beforeLoad
, grab the parameter info and set it into that field in
pageInit
, and then use that info for the redirect in
afterSubmit
. But I'd have to imagine that you could skip the client-side portion of that since the parameters should be available in
beforeLoad
.
n
Here is my code. first part at top
m
Strange, I don't see anything wrong with how you're getting the parameters. I personally wouldn't trust the global variable to persist into
afterSubmit
, but that shouldn't affect whether or not
scriptContext.request.parameters.rtype
shows
scriptContext.request
as undefined per your error (I'm assuming that's the line that the previously-mentioned error is occurring on). Maybe try logging
scriptContext
to see what its properties are in case something unexpected is going on there?
n
@MTNathan thanks, i'll see what i can figure out
🤞 1
👍 1