调用外部API获取文件并将其附加到Notes中

问题描述 投票:0回答:1

我有一个按钮,用户单击它,JavaScript 向外部 API 发出 GET 请求以创建 Excel 文件。我希望将此 Excel 文件附加到注释记录中并显示在时间线中。 虽然我已经通过 javascript 创建了请求并且正在生成 excel 文件,但我不知道如何“获取”此文件并将其附加到 CRM 中

function sendQuoteWithAPI(quoteId, selectedItems) {
                    var sendQuoteProcess = [];
                    var tokenId = 'tokenid';
                    ISV_abs_CloseDialog('ok');
                    var confirmStrings = {
                        text: "Excel file is being created. \n The file will be uploaded to timeline. \n\n\n Click Cancel if you don't want to proceed.",
                        title: "Export to Excel Confirmation!", confirmButtonLabel: "OK"
                    };
                    var confirmOptions = { height: 200, width: 400 };
                    //let test = "Excel file is being created. \n The file will be uploaded to timeline";
                    //window.parent.Xrm.Navigation.openAlertDialog({ text: test }, { height: 200, width: 300 });
                    var endpointURL = 'https://dynamics365-excelexport-dev.azurewebsites.net/api/export-quote?quoteId='+quoteId+'&customer='+selectedItems;
                    var requestOptions = {
                        method: 'GET',
                        headers: {
                            'Token': tokenId
                        }};
                    fetch(endpointURL, requestOptions)
                        .then(response => response.blob())
                        .then(result => console.log(result))
                        .catch(error => console.log('error:', error));
                }
javascript dynamics-crm microsoft-dynamics dynamics-365
1个回答
0
投票

首先您需要将文件内容作为 Base64 编码的字符串

此要点提供了如何实现此目的的示例:https://gist.github.com/n1ru4l/dc99062577b746e0783410b1298ab897

一旦获得了作为文件的 Base64 编码字符串,您需要使用以下结构创建一个

annotation
记录:

  • objectid:对要附加注释的记录的实体引用
  • isdocument: true
  • 文件名:您的文件名称.xlsx
  • 文档正文:
© www.soinside.com 2019 - 2024. All rights reserved.