简体   繁体   中英

Get value into HTML web resource in Dynamics CRM Online

I am trying to get a value from Dynamics CRM into a HTML webresource. I have found this and tried to make the code out of it:

https://msdn.microsoft.com/en-us/library/jj602964(v=crm.7).aspx

It says to use var nameValue = Xrm.Page.getAttribute("name").getValue(); to get it out.

My Code is (the alert is just to try if it gets the right value):

<html><head>
<meta charset="utf-8">
</head>
<body>
<button onclick="getquotenumber()">Try it</button>
<script>
function getquotenumber() {
    var getquote = Xrm.Page.getAttribute("quotenumber").getValue();
    alert(getquote);
}
</script>
</body></html>

When clicking "Try it" nothing happens! What am I doing wrong?

Thanks, Johannes

As someone already mentioned in the comments, there is no Xrm.Page defined. You can add that by referencing ClientGlobalContext but you would not have gotten any attributes anyway, because this is using Xrm.Page.data under the covers and this is null when you are not inside a CRM form. https://msdn.microsoft.com/en-us/library/gg328541.aspx

<script src="ClientGlobalContext.js.aspx" type="text/javascript"></script>

The simplest thing for only getting this one value is using the parent to get values on the form: window.parent.Xrm.Page.getAttribute("quotenumber").getValue();

Other options, pass values to your webresource: https://msdn.microsoft.com/en-us/library/gg327945.aspx

Or use the OData API: https://msdn.microsoft.com/en-us/library/gg334279.aspx

使用parent.Xrm.Page.getAttribute("quotenumber").getValue();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM