[英]How to pass CRM Dynamics 2015 Form data(filed values) to an HTML page which has JavaScript functions
I recently acquired a JavaScript API for a web-phone web client.我最近获得了一个用于网络电话网络客户端的 JavaScript API。 From CRM I want to launch this client and pass my CRM Form data to it, I have created a custom ribbon button that has to call that HTML Page and pass relevant data to it.我想从 CRM 启动这个客户端并将我的 CRM 表单数据传递给它,我创建了一个自定义功能区按钮,该按钮必须调用该 HTML 页面并将相关数据传递给它。
The ribbon button should launch the URL to the web-phone, but at the same time pass parameters to the JavaScript functions in the HTML page, do I use JavaScript action on ribbon or do I use URL action , if I use URL how do I pass data to the JScript function?功能区按钮应该启动网络电话的 URL,但同时将参数传递给 HTML 页面中的 JavaScript 函数,我是在功能区上使用 JavaScript 操作还是使用 URL 操作,如果我使用 URL 我该怎么做将数据传递给 JScript 函数?
To make this clearer I have a Contact entity in CRM which has a mobile number that I want to pass as a parameter to the HTML page that has the JavaScript functions I want to utilize for the web-phone client为了更清楚地说明这一点,我在 CRM 中有一个 Contact 实体,它有一个手机号码,我想将它作为参数传递给 HTML 页面,该页面具有我想用于网络电话客户端的 JavaScript 函数
If you are using an url to call the external page you can append the parameters as a "GET" so after calling the page:如果您使用 url 调用外部页面,则可以在调用页面后将参数附加为“GET”:
page.html?phone=123123 page.html?phone=123123
then you will be able to access that from your html page as this other post states Get url parameter jquery Or How to Get Query String Values In js and you should be fine.那么您将能够从您的 html 页面访问它,因为其他帖子指出获取 url 参数 jquery 或如何在 js 中获取查询字符串值,您应该没问题。 Also if you use it as an embedded web resource in the page you will be able to access the form properties via windows.parent.Xrm此外,如果您将其用作页面中的嵌入式 Web 资源,您将能够通过 windows.parent.Xrm 访问表单属性
Add line below to head tag of html:将下面的行添加到 html 的 head 标签:
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
Also add this code for running in case of loading of html:还要添加此代码以在加载 html 时运行:
<script src="OnLoadHtml.js" type="text/javascript"></script>
in javascript OnLoadHtml.js add these codes below:在 javascript OnLoadHtml.js 中添加以下代码:
document.onreadystatechange = function () {
//When document is ready
if (document.readyState == "complete") {
//Get sent arguments in url
var arguments = GetQueryArgument();
//Decode encoded arguments
var decodedArguments = decodeURIComponent(arguments)
}
}
//Gets query passed argument
function GetQueryArgument()
{
/*Get the any query string parameters and load them
into the vals array*/
var result = "";
var vals = new Array();
if (location.search != "") {
vals = location.search.substr(1).split("&");
for (var i in vals) {
vals[i] = vals[i].replace(/\+/g, " ").split("=");
}
//look for the parameter named 'data'
var found = false;
for (var i in vals) {
if (vals[i][0].toLowerCase() == "data") {
result = vals[i][1];
found = true;
break;
}
}
if (!found)
{
result = "";
}
}
else
{
result = "";
}
return result;
}
To return result from html to javascript back:要将结果从 html 返回到 javascript:
Add line below to body tag of html:将下面的行添加到 html 的 body 标签中:
<input id="btnOk" type="button" class="NormalButton" value="OK" onclick="BtnOK_OnClick();">
And add this code below for javascript part:并在下面为 javascript 部分添加此代码:
//On ok button pressed
function BtnOK_OnClick() {
debugger;
console.log("Ok is clicked");
var result = GetResult();
//Control value is not empty
if (result === "")
{
retrun;
}
Mscrm.Utilities.setReturnValue(result);
try
{
closeWindow(true); // Close the dialog box
}
catch (e)
{
console.log("Error happened at closing.");
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.