从消息记录中查询附件

Query attachment from a Message record

通过 UI,我创建了多个附加到支持票记录的消息记录,其中两个具有文件附件。我已经能够在 Suitescript 中检索到票证及其相关消息——它们正确地将 hasAttachment 报告为 'T'——但我似乎无法访问附件本身。文档指出附件是一个名为 'mediaitem'(或 'mediaitemlist',具体取决于您查看的位置)的子列表,但是 none 的子列表 API 在这些名称上取得了成功。

    var record = nlapiLoadRecord('message', 1092823, {recordmode: 'dynamic'});
    var itemCount = record.getLineItemCount('mediaitem');
    // returns -1

文档和其他联机信息非常少,因此我们将不胜感激。

是的,确实有一个糟糕的文档。 mediaitem 子列表也没有帮助我给出任何有意义的结果。

但是,还有一个替代解决方案。

Create a saved search from UI on message record type.

Make sure you add a search column Attachments : Internal ID (i.e. using attachment fields...)

完成后,运行您在 suitescript 中的搜索为

var res = nlapiSearchRecord('message', 'YOUR_UI_SEARCH_ID', ARRAY_OF_ADDITIONAL_FITLTERS);
res[i].getValue('internalid', 'attachments')

这就是您在 Suitescript 2.0 中的实现方式。首先搜索邮件 ID,然后搜索与这些邮件 ID 相关的附件。您可以即时创建搜索,因此无需保存搜索。

如果您想根据您的场景保存治理点,您可以传递案例或消息的内部 ID 数组。

注意:以下代码示例假定您将搜索模块加载为 SEARCHMODULE。


第 1 步 - 这是如何从支持案例记录中获取带有附件的消息 ID(只需将类型更改为支持票):

function getMessageIdsFromCase(supportCaseId){
    var supportcaseSearchObj = SEARCHMODULE.create({
       type: "supportcase", //Change if you  need to
       filters: [
          ["internalid","anyof",supportCaseId], 
          "AND", 
          ["messages.hasattachment","is","T"]
       ],
       columns: [
          SEARCHMODULE.createColumn({
             name: "internalid",
             join: "messages"
          })
       ]
    });

    var resultsSet = supportcaseSearchObj.run();
    var results = resultsSet.getRange(0, 999);

    var messages = [];
    for (var i in results) {
        var result = results[i];
        var message = result.getValue(result.columns[0]);
        messages.push(message);
    }
    return messages;
}

然后你就这样调用这个函数:

getMessageIdsFromCase(caseInternalId); //Returns an array of message ids

第 2 步 - 然后使用邮件内部 ID 和此功能搜索附件:

function getAttachmentIdsFromMessage(messageInternalId){
    var messageSearchObj = SEARCHMODULE.create({
       type: "message",
       filters: [
          ["internalid","anyof",messageInternalId]
       ],
       columns: [
          SEARCHMODULE.createColumn({
             name: "internalid",
             join: "attachments"
          })
       ]
    });
    var resultsSet = messageSearchObj.run();
    var results = resultsSet.getRange(0, 999);

    var attachments = [];
    for (var i in results) {
        var result = results[i];
        var attachment = result.getValue(result.columns[0]);
        attachments.push(attachment);
    }

    return attachments;
}

然后你就这样调用这个函数:

getAttachmentIdsFromMessage(messageInternalId); //Returns an array of attachment ids

更新:

提交案例后收到 NS 的消息。似乎还不支持:

Hi Shane,

I hope you are doing well today.

Upon checking, the ability to access files attached to records are not yet supported in SuiteScript. You can check out SuiteScript Records Browser at SuiteAnswers ID 10511 for the full list of all available records in SuiteScripts and each's accessible sublist. Let me know if you have further questions.

Caleb Francisco | Customer Support NetSuite: Where Business is Going

使用 search.createColumn 与连接是它看起来像的关键。我最终使用下面的快速代码来获取附加到 $transaction (returnauthorization) 的任何 $files (html),在我的例子中,这应该是 return 上的 mediaitems auth 我无法通过 ss2.0

中的记录模块获得
var getHtmlFilesOnReturnAuth = function (return_auth_id, file_type) {
    var filters = [
        search.createFilter({name: "internalid", operator: "is", values: [return_auth_id]}),
        search.createFilter({name: "filetype", join: "file", operator: "is", values: [file_type]}),
    ];
    var images = [];
    search.create({
        type: "returnauthorization",
        filters: filters,
        columns: [
            search.createColumn({name: "internalid", summary: "group"}),
            search.createColumn({name: "internalid", join: "file", summary: "group"}),
            search.createColumn({name: "filetype", join: "file", summary: "group"}),
            search.createColumn({name: "name", join: "file", summary: "group"}),
        ]
    }).run().each(function (result) {
        if (result) {
            images.push({
                id: result.getValue({name: "internalid", join: "file", summary: "group"}),
                file_name: result.getValue({name: "name", join: "file", summary: "group"}),
                file_type: result.getValue({name: "filetype", join: "file", summary: "group"}),
            });
        }
        return true;
    });

    return images;
};

var images = getHtmlFilesOnReturnAuth("2134404", "HTMLDOC");