简体   繁体   English

如何在JavaScript中使用Base64String值设置Dynamics CRM / 365字段

[英]How to set a Dynamics CRM/365 field with Base64String value in JavaScript

I want to set the "base64string" with the base 64 string value of a document, then I will later take that value and load the document onto sharepoint(I already have the c# code for this working through a console application). 我想使用文档的基数64字符串值设置“ base64string”,然后稍后再使用该值并将文档加载到sharepoint(我已经有了通过控制台应用程序进行操作的c#代码)。

My code below does not seem to work, basically the value is never set, The field base64string is a multi-line with 1 million characters. 我的以下代码似乎无法正常工作,基本上从未设置过该值,base64string字段是一个包含100万个字符的多行。

<html>
<head>
  <meta charset="utf-8">
</head>
<body>
  Please select a file and then hit Evaluate:
  <br/>
  <input id="file" type="file" />
  <button id="button">Upload        
    <script>           
      document.getElementById('button').addEventListener('click', function() {
        var files = document.getElementById('file').files;
        if (files.length > 0) {
          getBase64(files[0]);
        }
      });

      function getBase64(file) {
        var reader = new FileReader();
        reader.readAsDataURL(file);
        reader.onload = function () {        
          Xrm.Page.getAttribute("base64string").setValue(reader.result);
        };
        reader.onerror = function (error) {};
      }        
    </script>      
</body>
</html>

In Xrm.Page.getAttribute("base64string") , are you certain base64string is a field name? Xrm.Page.getAttribute("base64string") ,您确定base64string是字段名称吗? If its a custom field it should have a prefix such as abc_base64string . 如果它是一个自定义字段,则应具有一个前缀,例如abc_base64string

Furthermore a HTML web resouce can't directly access Xrm.Page . 而且,HTML Web资源无法直接访问Xrm.Page

Reference other web resources from an HTML web resource . 从HTML Web资源引用其他Web资源

An HTML web resource added to a form can't use global objects defined by the JavaScript library loaded in the form. 添加到表单的HTML Web资源不能使用由表单中加载的JavaScript库定义的全局对象。 An HTML web resource may interact with the Xrm.Page or Xrm.Utility objects within the form by using parent.Xrm.Page or parent.Xrm.Utility , but global objects defined by form scripts won't be accessible using the parent. HTML Web资源可以通过使用parent.Xrm.Pageparent.Xrm.Utility与表单中的Xrm.PageXrm.Utility对象进行交互 ,但是由表单脚本定义的全局对象将无法使用父级进行访问。

I belive your code should look more like this: 我相信您的代码应该看起来像这样:

reader.onload = function () {        
    parent.Xrm.Page.getAttribute("abc_base64string").setValue(reader.result);
};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Microsoft dynamics crm 365中通过javascript获取查找字段的值 - How can I get the value of a lookup field by javascript in Microsoft dynamics crm 365 使用javascript将base64string转换为可下载文件 - Convert base64string to downloadable file using javascript JavaScript base64string -&gt; 二进制值 -&gt; [Integer]... 性能提升 - JavaScript base64string -> binary values -> [Integer] ... performance improvement 如何使用JavaScript将Byte []格式化图像转换为Base64string - How to convert Byte[] formated image to Base64string using JavaScript 如何使用 Base64string PDF 数据 - How to use with Base64string PDF data 无法为自定义字段Dynamics 365设置值 - Unable to set value to custom field Dynamics 365 Dynamics365。字段值(javascript) - Dynamics 365. Field value (javascript) 在JQuery中将图像转换为base64string - Convert image into base64string in JQuery Javascript / MS Dynamics CRM 2016:使用确认框更改选项集字段的值 - Javascript / MS Dynamics CRM 2016: Changing value of option set field using confirm box JAVASCRIPT将base64字符串(已编码的zip文件)解码为zip文件,并按名称获取zipfile的内容 - JAVASCRIPT decode a base64string (which is an encoded zipfile) to a zipfile and get the zipfiles content by name
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM