Hi all, I copied the event script from Netsuite b...
# suitescript
k
Hi all, I copied the event script from Netsuite but when I use log.debug(context) it does not seem to be triggered when I create a sales order?
Copy code
/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
 define(['N/record'], function(record) {
    function beforeLoad(context) {
        if (context.type !== context.UserEventType.CREATE)
                return;
        var customerRecord = context.newRecord;
        customerRecord.setValue('phone', '<tel:555-555-5555|555-555-5555>');
        if (!customerRecord.getValue('salesrep'))
            customerRecord.setValue('salesrep', 46); // replace '46'  with one specific to your account
    }
    function beforeSubmit(context) {
        if (context.type !== context.UserEventType.CREATE)
            return;
        var customerRecord = context.newRecord;
        customerRecord.setValue('comments', 'Please follow up with this customer!');

        if (!customerRecord.getValue('category')) {
            throw error.create({       // you can change the type of error that is thrown
                name: 'MISSING_CATEGORY',
                message: 'Please enter a category.'
            })
        }
    }
    function afterSubmit(context) {
        if (context.type !== context.UserEventType.CREATE)
            return;
        var customerRecord = context.newRecord;
        if (customerRecord.getValue('salesrep')) {
            var call = record.create({
                type: record.Type.PHONE_CALL,
                isDynamic: true
            });
            call.setValue('title', 'Make follow-up call to new customer');
            call.setValue('assigned', customerRecord.getValue('salesrep'));
            call.setValue('phone', customerRecord.getValue('phone'));
            try {
                var callId = call.save();
                log.debug('Call record created successfully', 'Id: ' + callId);
            } catch (e) {
                log.error(e.name);
            }
        }
    }
    return {
        beforeLoad: beforeLoad,
        beforeSubmit: beforeSubmit,
        afterSubmit: afterSubmit
    };
});
s
dont you need N/log?
🤦‍♂️ 1
k
Oh my god small mistake, let me double try
Thank you !
🙌 1
It is so weird, I never used N/log for my restlet. Is this something that is required for user event script?
s
i guess so. I havent used restlets myself
k
I see, I updated the script but still not triggered when I created a sales order
w
Is it deployed properly? Do you have too many userevent scripts on the record already?
k
@Watz thank you, I got it working, it had to do with deploying improperly
c
FYI you never have to include N/log explicitly as its provided.
👀 1
👍 4
✔️ 1