2

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

Bassetassen
  • 20,852
  • 8
  • 39
  • 40

2 Answers2

0

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

Bassetassen
  • 20,852
  • 8
  • 39
  • 40
  • The eventual goal is to create a button with a link that contains one dynamic URL Parameter for each quote (quotenumber). To do this I use a HTML web resource to create the button and thought to use Java Script to create the dynamic link. Is this even possible? – Johannes Linder Apr 16 '15 at 09:18
  • @JohannesLinder If you use the window.parent.Xrm.. you can get the value of any attribute on the parent form. If you only want a button, you can have a button in the command bar instead of using a HTML webresource. – Bassetassen Apr 16 '15 at 09:36
  • Are you sure that you can add buttons in the MS Dynamics Online command bar? I have only found MS Dynamics CRM 2013... – Johannes Linder Apr 16 '15 at 10:08
  • @JohannesLinder Yes, that's possible. Exactly the same way to do it online and on-prem. I like to use this tool when I create buttons. https://ribbonworkbench.uservoice.com/knowledgebase/articles/80806-download-ribbon-workbench-for-crm-2011-2013-2015 – Bassetassen Apr 16 '15 at 10:45
0

Use parent.Xrm.Page.getAttribute("quotenumber").getValue();

Aleksandr M
  • 24,264
  • 12
  • 69
  • 143
  • Welcome to Stack Overflow! Please consider editing your post to add more explanation about what your code does and why it will solve the problem. An answer that mostly just contains code (even if it's working) usually wont help the OP to understand their problem. – SuperBiasedMan Sep 02 '15 at 13:35