簡體   English   中英

通過電子郵件發送Javascript附件

[英]Javascript attachment via email

我需要JavaScript函數方面的幫助。 我正在使用ServiceNow平台。

我有要求:

  • 使用電子郵件客戶端發送時,自動將附件添加到事件記錄中(Works,但是一次更新將附件添加到記錄中兩次,每次都重新添加所有附件)
  • 在活動日志中跟蹤更改(我正在執行此操作)這些鏈接中發布的解決方案使我接近,但存在問題。 https://community.servicenow.com/thread/163398

我正在使用“ 精英”頁面上發布的代碼。

問題:

  • 通過電子郵件客戶端添加的單個附件被添加到記錄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();
        }
    } 
}

您是否考慮過消除while(grTargetTable.next())塊? 只需一次手動對grTargetTable.next()進行操作,因為您是通過sys_id查詢的,因此應該只有一個。

我想知道是否有任何效果。 抱歉,我無法直接評論您的問題,我的代表還不夠。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM