I'm trying to create my first user event script an...
# suitescript
h
I'm trying to create my first user event script and am running into issues trying to set any field on the task record? Are there any good debug methods or does anyone know what could be causing the issue? I am just trying to get this code to run as a baseline.
Copy code
/**
 *@NApiVersion 2.1
 *@NScriptType UserEventScript
 */


define ( ['N/record', 'N/ui/serverWidget'] ,
    
    function(record, serverWidget) {

        
        function myBeforeSubmit(context) {
            if (context.type !== context.UserEventType.CREATE)
                return;
            var newEmployeeRecord = context.newRecord;
            newEmployeeRecord.setValue({
                fieldId: 'message',
                value: 'Orientation date TBD.'
            });
        }
        
        return {
            beforeSubmit: myBeforeSubmit
        };
    });
j
What does your deployment record look like?
h
@JessicaL
j
Click on the deployment record itself. Make sure you have it turned on for the role you're using.
The audience tab is where you'll define the roles.
h
Still getting this:
message has been deleted
message has been deleted
j
The very helpful "Unexpected error." Thanks, NetSuite. Very strange. Your code works perfectly fine in my account without any changes needed. Are you getting that error when saving or when opening up a Task?
h
When saving the task
I did notice this too
j
Yeah, I've got the same bundle installed. Hm, I really hate undefined errors. If you comment out all of your code and just log a string or something, do you get an error? I don't see any issue with your code. Which may mean something else in netsuite is messing with you. Like, for example, you don't have SuiteScript enabled in your general settings or something. Or something else is creating this error (like a workflow or something) and the timing just seems to be the upload of this code.
h
Even without logging anything I am still getting that error.
Copy code
/**
 *@NApiVersion 2.1
 *@NScriptType UserEventScript
 */

// Load two standard modules.
define ( ['N/record', 'N/ui/serverWidget'] ,
    // Add the callback function.
    function(record, serverWidget) {

        // In the beforeSubmit function, add test to the Notes field.
        function myBeforeSubmit(context) {
            //if (context.type !== context.UserEventType.CREATE)
                //return;
            //var newEmployeeRecord = context.newRecord;
            //newEmployeeRecord.setValue({
                //fieldId: 'message',
                //value: 'Orientation date TBD.'
            //});
        }
        // Add the return statement that identifies the entry point funtions.
        return {
            beforeSubmit: myBeforeSubmit
        };
    });
disabling the code works perfectly fine. Also suitescript is working on my client script perfectly fine.
j
Man alive, wish I knew what was causing it. We've all been here at some point and it's usually something real silly happening (but hard to pin down with such a basic error msg). In my experience, my next course of action would be to open up your Scripted Records page for Tasks, disable all other scripts and workflows that are running, see if I still get the error. If the error goes away, then enable everything piece by piece until you get it. That'll tell you what's bumping into it.
h
@JessicaL Thanks for your help. Went through it with a Netsuite tech and I just needed to re-create the script records 🙃
j
🙃 indeed. I'm glad you figured it out. Gotta love a ghost in the machine.