通过电子邮件发送Javascript附件

时间:2015-05-28 23:56:40

标签: javascript email servicenow

我需要JavaScript函数的帮助。我正在使用ServiceNow平台。

我有以下要求:

  • 使用电子邮件客户端发送时自动将附件添加到突发事件记录(Works,但在一次更新中将附件添加到记录中两次,并且每次都重新添加所有附件)
  • 跟踪活动日志中的更改(我有一个工作) 这些链接中发布的解决方案让我接近但有问题。 https://community.servicenow.com/thread/163398

我正在使用Elite page here中发布的代码。

问题:

  • 通过电子邮件客户端添加的单个附件将添加到记录TWICE
  • 稍后通过电子邮件客户端添加其他附件时,将重新附加所有以前的附件

为什么要将附件添加到记录中两次? 如何通过电子邮件客户端获取最新更新中添加的附件?

//Table: Email [sys_email]
//When: after 
//Insert: true
//Update: true
//Condition: !current.instance.nil() && current.type == 'received'
//Script:
addAttachmentAudit();
function addAttachmentAudit() {
    var instance = current.instance;
    var targetTable = current.target_table;
    var grAttachment = new GlideRecord('sys_attachment');
    grAttachment.addQuery('table_sys_id',current.sys_id);
    grAttachment.query();
    while(grAttachment.next()){
        grAttachment.table_name = targetTable;
        grAttachment.table_sys_id = instance;
        grAttachment.update();
        var grTargetTable = new GlideRecord(targetTable);
        grTargetTable.addQuery('sys_id',instance);
        grTargetTable.query();
        while (grTargetTable.next()) { 
            grTargetTable.work_notes = 
                "Attachment added: " + grAttachment.file_name + 
                " by email from " + current.sys_created_by;
            grTargetTable.update();
        }
    } 
}

1 个答案:

答案 0 :(得分:0)

您是否考虑过删除while(grTargetTable.next())块?只需要手动grTargetTable.next()一次,因为你要通过sys_id查询,因此应该只有一个。

我有兴趣知道这是否有效。 对不起,我无法直接评论你的问题,我还没有足够的代表。

相关问题