admin管理员组文章数量:1405727
I am working on Microsoft Dynamics CRM 2016. I have a description
field on my Lead form along with that I have added an HTML web resource. When I enter a description
value on the CRM form, it should display on my HTML web resource.
How can this be achieved?
HTML web resource code:
<html>
<head>
<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script text="text/javascript">
var description = Xrm.Page.getAttribute("description").getValue();
</script>
</head>
<body>
<table>
<thead><tr><th>Parameter</th><th>Value</th></tr></thead>
<tbody>
<tr><td>description</td><td id="description">null</td></tr>
</tbody>
</table>
</body>
</html>
Then in the web resource's properties I have:
- added a custom parameter: (data)= RelatedEntity=leads&RelatedField=description
- enabled the option to pass record object-type code and unique identifier as parameters
- added
description
in dependencies
I am working on Microsoft Dynamics CRM 2016. I have a description
field on my Lead form along with that I have added an HTML web resource. When I enter a description
value on the CRM form, it should display on my HTML web resource.
How can this be achieved?
HTML web resource code:
<html>
<head>
<script src="../ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script text="text/javascript">
var description = Xrm.Page.getAttribute("description").getValue();
</script>
</head>
<body>
<table>
<thead><tr><th>Parameter</th><th>Value</th></tr></thead>
<tbody>
<tr><td>description</td><td id="description">null</td></tr>
</tbody>
</table>
</body>
</html>
Then in the web resource's properties I have:
- added a custom parameter: (data)= RelatedEntity=leads&RelatedField=description
- enabled the option to pass record object-type code and unique identifier as parameters
- added
description
in dependencies
- You should expand the question to show you tried to solve the problem (i.e. describe one or more solutions you attempted but don't work for you and specify why they don't work for you) otherwise the question is going to be downvoted and ignored because of lack of research on your part. Also, include the CRM version (2016 means 8.0 or 8.1 ?) – Alex Commented May 8, 2017 at 11:58
3 Answers
Reset to default 2You could attach a JavaScript onChange() event to the description
attribute. The event would get the value of the description, then get the element from your HTML control and then set the element's value equal to the description
attribute's value.
Here's an example of how it might look:
function descriptionOnChange() {
// Get the value of the description attribute.
var description = Xrm.Page.getAttribute('description').getValue();
// Get the HTML iFrame object.
var iFrame = Xrm.Page.ui.controls.get('IFRAME_WebResourceName').getObject();
// Get the element from the iFrame.
var element = iFrame.contentWindow.document.getElementById('htmlDescription');
// Set the element's value.
element.value = description;
}
Note: ensure cross-frame scripting is not disabled in your iFrame's properties:
You may however receive an error if cross-domain iFrame requests are blocked. See this post for an explanation and workaround.
The workaround's implementation in CRM might look like this:
Add a
<script>
tag to your HTML's<body>
to accept and process a message:<script> window.addEventListener('message', function(event) { if (~event.origin.indexOf('https://<yourCRMUrl>')) { document.getElementById('htmlDescription').value = event.data; } else { return; } }) </script>
Change the contents of your
description
attribute's onChange() event to this:var description = Xrm.Page.getAttribute("description").getValue(); var iFrame = Xrm.Page.ui.controls.get('IFRAME_WebResourceName').getObject(); iFrame.contentWindow.postMessage(description, '*');
You can try something like this:
<html>
<head>
<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>
<script type="text/javascript">
function onLoad() {
var description = parent.Xrm.Page.getAttribute("description").getValue();
document.getElementById("description").innerHTML = description;
}
</script>
</head>
<body onload="onLoad()">
<table>
<thead><tr><th>Parameter</th><th>Value</th></tr></thead>
<tbody>
<tr><td>description</td><td id="description">null</td></tr>
</tbody>
</table>
</body>
</html>
Also, as your code grows you can move it into its own web resource, and include it in the html head like this:
<script src="myLibrary.js" type="text/javascript"></script>
I've put my button on Account.
HTML:-
<html>
<head>
<meta>
</head>
<body onfocusout="parent.setEmailRange();" style="overflow-wrap: break-word;">
<p>Account Name:</p>
<p id="accountName"></p>
<p>Telephone:</p>
<p id="telephone"></p>
<p>Fax:</p>
<p id="fax"></p>
<p>Website URL:</p>
<p id="websiteUrl"></p>
<script>
//<!-- Retrieving Window URL -->
var url = window.location.href;
//<!-- Processing The Data From URL -->
var dataIndex = url.lastIndexOf("=") + 1;
var dataLength = url.length;
var recordData = url.slice(dataIndex, dataLength);
var processedRecordData = decodeURIComponent(recordData.replace(/\+/g, ' '));
//<!-- Splitting the processedRecordData into separate values -->
var values = processedRecordData.split(",");
//<!-- Appending Data to HTML Elements -->
document.getElementById("accountName").innerHTML = values[0] || "";
document.getElementById("telephone").innerHTML = values[1] || "";
document.getElementById("fax").innerHTML = values[2] || "";
document.getElementById("websiteUrl").innerHTML = values[3] || "";
</script>
</body>
</html>
JavaScript:-
function getValue(primarycontrol) {
var formContext = primarycontrol;
var AccountName = formContext.getAttribute("name").getValue();
var Telephone = formContext.getAttribute("telephone1").getValue();
var Fax = formContext.getAttribute("fax").getValue();
var WebsiteUrl = formContext.getAttribute("websiteurl").getValue();
var windowsoption = { height: 400, width: 400 };
var parameters = encodeURIComponent(AccountName) + ',' +
encodeURIComponent(Telephone) + ',' +
encodeURIComponent(Fax) + ',' +
encodeURIComponent(WebsiteUrl);
Xrm.Navigation.openWebResource("ispl_HTML_Form", windowsoption, parameters);
}
本文标签: javascripthow to get value from microsoft dynamics crm form to html web resourceStack Overflow
版权声明:本文标题:javascript - how to get value from microsoft dynamics crm form to html web resource - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744921595a2632327.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论