How to Invoke Button Function with Client Script
I’ve added a button with a beforeLoad UE script. When the user clicks the button, it should create a new instance of a custom record. As I understand, you need a client script to handle the button click. I seem to be having trouble invoking my button function, though. I set the name of the function when I created the button in the UE script. Then I defined the named function in my client script. But when the button is clicked, the function in the client script is never invoked. Anyone know what I’m missing?
You have to open the Console on your browser as it seems to me your client script is throwing an error, particularly on this line:
record.create({ type : 'custrecord_trainevent' });
‘custrecord_trainevent’ is not a record type, it is a field name. You have to change it to the correct ID of the Custom Record type.
I tried mimicking your script and it returned this error on the Console: uncaught exception: {“type”:”error.SuiteScriptError”,”name”:”INVALID_RCRD_TYPE”,”message”:”The record type [CUSTRECORD_TRAINEVENT] is invalid.
If the client function is still not getting called even after correcting this line, you have to continue debugging until the client script is 100% error free.
Can you share the simplified code of your User Event and Client Script? Are you sure that you are setting this line properly? It should reference the correct directory of the file.
context.form.clientScriptModulePath = './LEACC_CL_for_Suitelet.js';
Initially, i figured out the problem was i wasn’t specifying the client script. I tried adding it with context.form.clientScriptFileId, but i kept getting an API version error. Maybe it’s deprecated? At any rate, i switched to context.form.clientScriptModulePath, like in your example. There’s no error anymore, but still, it’s not invoking the function in the client script when the button is clicked. I know because I have a log entry when it first enters the function in the client script, but the log never occurs.
Here’s the user event script:
And here’s the client script:
Any thoughts? At this point, I’m just trying to get it to step into the function for the button.
Right. Referencing custom records can be funky sometimes, and I knew that line could cause problems. But, that still doesn’t explain why it’s not executing the log statement before it gets to the record creation. I should at least get a log, if the function is actually being invoked, then the script throws an error for the record creation. Follow me? Since I’m not even getting that initial log, that leads me to believe the function is not being invoked at all for some reason, and I can’t figure out why.
To demonstrate my point, I commented out everything in the client script function except the log. I don’t get any error, but I’m also not getting the log, which means the function is not being invoked.
The log wouldn’t show up in the User Event script record, as you’re on the client-side perspective when you’re expecting this. You’re better off using console.log if troubleshooting is your goal.
Yeah but you should still be able to see it in the logs for the client script. I can do a log for the pageInit function and see it just fine.
It looks like you’re right. You do have to use console.log to see any of the logs.
From there, i figured out the type property of record.create should be the custom record ID (e.g. ‘customrecord_trainevent’). I was getting an error with this for a while because i had the prefix wrong. In the end, though, I realized what I’m actually looking to do is not use record.create, but rather redirect the user to the entry form so they can enter the data and create the new record in the UI.

Moving forward, avoid asking follow up questions as much as possible as it makes the thread harder to read. For example, you entitled the question “How to Invoke Button Function with Client Script” and then later on you asked about viewing the logs from the client script.
follow on this Github: https://github.com/HarishBakka/SuiteScript/tree/main
There are two scenarios button can be used
- using currentRecord.get() by passing currentRecord as module https://github.com/HarishBakka/SuiteScript/commit/e044ef9b003333a02515bc1cd788f8128910923a
- Function invoke and sending record data as an argument https://github.com/HarishBakka/SuiteScript/commit/7944b0be5903f964162f80b22307a689dcdad078