Netsuite 当销售记录中的客户字段由值输入时,应自动填充自定义字段(主要联系人和主要电子邮件)的Suitescript

Netsuite 当销售记录中的客户字段由值输入时,应自动填充自定义字段(主要联系人和主要电子邮件)的Suitescript,netsuite,suitescript,erp,suitescript2.0,Netsuite,Suitescript,Erp,Suitescript2.0,应从销售订单中提到的特定客户处检索主要联系人和电子邮件信息 我尝试了以下代码,但无法从客户记录中检索角色(主要联系人)。在销售订单中输入customer字段时,我得到的是null值(空),并且没有自动填充自定义字段 function fieldChanged(context) { var sales=context.currentRecord; if(context.fieldId=='entity') { v

应从销售订单中提到的特定客户处检索主要联系人和电子邮件信息

我尝试了以下代码,但无法从客户记录中检索角色(主要联系人)。在销售订单中输入customer字段时,我得到的是null值(空),并且没有自动填充自定义字段

function fieldChanged(context) 
    {

        var sales=context.currentRecord;

        if(context.fieldId=='entity')
        {
            var cusid=sales.getValue('entity');

            var cust=record.load({
                type: record.Type.CUSTOMER,
                id:cusid
            });

            var custid=cust.getText('entityid');

            log.debug(custid);


            var roleCount= cust.getLineCount({
                sublistId :'contactroles',

            });

            log.debug('count',roleCount);

            for(var i=0;i<roleCount;i++)
            {
                var roleName=cust.getSublistText({ sublistId : 'contactroles',fieldId : 'contactrole', line:i});

                log.debug('role',roleName);

                if(roleName=='Primary Contact')
                {
                    var emailinfo=cust.getSublistText({ sublistId : 'contactroles',fieldId : 'email', line:i});
                    sales.setValue('custbody_primary_email',emailinfo);
                }

            }

        }
    }

函数字段已更改(上下文)
{
var sales=context.currentRecord;
if(context.fieldId=='entity')
{
var cusid=sales.getValue(“实体”);
var cust=record.load({
类型:record.type.CUSTOMER,
id:cusid
});
var custid=cust.getText('entityid');
log.debug(custid);
var roleCount=cust.getLineCount({
子列表:'contactroles',
});
log.debug('count',rolecoount);

对于(var i=0;i在
contactroles
子列表中没有
contactrole
字段。有关正确的字段ID,请参阅
函数字段已更改(上下文){
试一试{
var sales=context.currentRecord;
if(context.fieldId=='entity')//检查光标是否在customer字段中
{
var cusid=sales.getValue('entity');//检索salesOrder中客户的id
var cust=record.load({//使用上述id加载客户记录
类型:record.type.CUSTOMER,
id:cusid
});
log.debug('customer id',cusid);
var custid=cust.getText('entityid');
log.debug(custid);
var roleCount=cust.getLineCount({//counting子列表(客户记录)中的行)
子列表:“联系人角色”
});
log.debug('count',rolecoount);
for(var i=0;i}
您需要引用客户字段“联系人”。此字段将为您提供主要联系人的内部id。从中,您可以建立一个逻辑来获取主要联系人的信息。

是的,这是真的。。但当我将其替换为“角色”时,我得到的是不同的角色,该角色不包括在角色列表中。实际上,我支持ed获得“主要联系人”