[英]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.Page或parent.Xrm.Utility与表单中的Xrm.Page或Xrm.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.