将变量从用户事件脚本传递到NetSuite中的客户端脚本

Bra*_*son 2 netsuite suitescript

我正在使用2个脚本在NetSuite中完成电子邮件功能。我有一个用户事件脚本,它创建一个按钮,一个客户端脚本,该脚本提取所有需要的变量,并根据在“销售团队”子列表中找到的值来运行电子邮件。这是我的问题:在测试脚本时,一切工作都很好,因为我正在以管理员角色进行测试(我知道是菜鸟错误)。当管理员以外的其他角色尝试通过单击按钮运行脚本时,由于角色权限问题​​(无法提取存储电子邮件地址的员工数据)而引发nlObjError。是否可以在UE脚本中提取我需要的所有变量(可以以Admin身份执行)并将它们传递给客户端脚本?

UE脚本:

function userEventCreateButton(type, form, request){

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

客户端脚本:

...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...
Run Code Online (Sandbox Code Playgroud)

pra*_*sun 5

另一个选择是,您可以将员工电子邮件添加到before load user event脚本中的隐藏字段,该 脚本已部署为以管理员身份运行,然后在您的客户端脚本中您可以阅读电子邮件

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

在客户端脚本中,您现在可以使用

var emploeeIdToEmails = JSON.parse(nlapiGetFieldValue('custpage_emails'));
Run Code Online (Sandbox Code Playgroud)