套件脚本:更新案例记录状态 - 如果收到客户消息



希望有人能帮我解决这个问题。如果收到客户交互(电子邮件(,我正在尝试触发案例状态更改。

以下是迄今为止编写的代码:

function afterSubmit(type)
{
//load the case record
var caseRecord = nlapiLoadRecord('supportcase', nlapiGetRecordId());
//Get the Case Status of the assoicated Case
var caseStatus = caseRecord.getFieldValue('status');
//Get the Message value
var incomming = caseRecord.getFieldValue('incomingmessage');  

//Check current Status is none of Completed or Closed
if(caseStatus != '4' && caseStatus != '5')
{
    // If there is any activity
    if(incomming != '')
    {
         // Load the message record
        var message = nlapiGetNewRecord();
        // Get the ID of the activity associated with the message
        var activity = message.getFieldValue('activity');
            if (activity)
            {
                // If the activity is a case, load the record and change the status.
                try
                {
                    var caseRecord = nlapiLoadRecord('supportcase', activity);
                    caseRecord.setFieldValue('status',20);
                    nlapiSubmitRecord(caseRecord);
                }
                // If the activity is not a Case, log a warning message
                catch(exec)
                {
                nlapiLogExecution('DEBUG', 'Warning','Activity Record is not a Case');
                }
            }
        else
        {
            return false;
        }
    }
    else
    {
        return false;
    }
}   

}

注意:案例状态 4 = 已完成案例状态 5 = 已关闭案例状态 20 = 收到的客户回复这是怎么回事?一旦我保存了案例并生成一封邮件给客户,即案例记录的电子邮件。案例状态更新为"已收到客户回复">

首先,我可以指出

if(caseStatus != '4' || caseStatus != '5')

将永远true. 您正在测试 CASEStatus 是不等于 4 还是不等于 5。 因此,如果它等于 4,它将不等于 5,因此为 true,反之亦然。 所以我认为你想做的是:

if(caseStatus != '4' && caseStatus != '5')

或:

if(!(caseStatus == '4' || caseStatus == '5'))

有了这个,看起来您正在加载案例并检查任何活动并基于此更改状态。 当您向客户发送电子邮件时,您正在创建活动,因此始终存在活动,因此状态将始终更新为"20"。 但是,似乎缺少一些代码,因为在脚本开始时,您将messagecaseRecord设置为同一内容,因此我可能误读了您在做什么。

相关内容

最新更新