Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass variable from User Event Script to Client Script in NetSuite

I am using 2 scripts to accomplish an email function in NetSuite. I have a User Event script that creates a button and a client script that pulls all the needed variables and runs the email based on a value found in the Sales Team sublist. Here is my issue: When testing the scripts everything worked great because I was testing with my Administrator role (rookie mistake I know). When a role other than Admin attempts to run the scripts via the button click, an nlObjError is thrown due to role permissions issues (can't pull employee data which is where the email address is stored). Is it possible to pull all the variables I need in the UE script (which can execute as Admin) and pass those to the client script?

UE Script:

function userEventCreateButton(type, form, request){

if (type != 'edit'){
        return;
    }
form.addButton('custpage_RequestSOW', "Request SOW", 'cs_RequestEmail()');
form.setScript('customscript224');  

Client Script:

...for (var y = 1; y <= nlapiGetLineItemCount('salesteam'); y++) {
        var z = nlapiGetLineItemValue('salesteam', 'salesrole', y);
        nlapiLogExecution('DEBUG', 'sales role', z);
        var user = nlapiGetUser();
        **var username = nlapiLoadRecord('employee', user);**
        var firstname = username.getFieldValue('firstname');
        var lastname = username.getFieldValue('lastname');
        var opptitle = nlapiGetFieldValue('title');
        var customer = nlapiGetFieldValue('customer');
        nlapiLogExecution('debug', 'user', user);
        if (z != 5){}
        else if (z == 5){
            var employee_name = nlapiGetLineItemValue('salesteam', 'employee', y);
            console.log(employee_name);
            **var engrecord = nlapiLoadRecord('employee', employee_name);**
            console.log(engrecord);
            var engemail = engrecord.getFieldValue('email');
            console.log(engemail);
            nlapiSendEmail(user...
like image 293
Brad Simpson Avatar asked Dec 20 '25 16:12

Brad Simpson


1 Answers

Another option is you can add the employees email to the hidden fields in before load user event script which is deployed to run as Administrator and then in your client script you can read the emails

//in a variable make a JSON of employee Ids to Emails
newForm.addField('custpage_emails', 'longtext','Email').setDisplayType(hidden).setValue(JSON.stringify(employeeIdEmails));

In client script you can now get the data using

var emploeeIdToEmails = JSON.parse(nlapiGetFieldValue('custpage_emails'));
like image 99
prasun Avatar answered Dec 24 '25 11:12

prasun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!