Translate

Tuesday, 23 July 2013

How to get CRM entity attribute value in HTML web resource

  Today i got the requirement of getting CRM entity attribute value in the html web resource which was attached with the crm entity or called on clicking on a navigation link or from a ribbon button.

    You can get parent window object and then you can get object of crmForm then you will get all attribute of entity as well as their values.

For CRM 2011 

var attrVal = window.parent.document.crmForm.<Attribute Name>.value;


For CRM 2013

var attrVal = window.parent.document.Xrm.Page.getAttribute("<Attribute Name>").getValue();


Step 1:- Add a HTML web resource which you want to use.

Step 2:- Add a java script function with the fallowing code in the head section of the HTML web resource.

 <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
               <script type="text/javascript">
                   function ABC() {
                       debugger;
                       var form = document.forms[0];
                       var context = GetGlobalContext();
                       var attrVal = window.parent.document.crmForm.<Attribute Name>.value;   
                       // Your code for your functionality                                                                                            }
 </script>
<meta charset="utf-8">
Step 3:- Call java script function on body on load.

<body onload="ABC()">
  
   <form method="post" action="">
    //******************************************
    //********* your HTML **********************
    //******************************************
   </form>

</body>
Your final HTML web resource will look like.
 
<html>
     <head>
          <title> </title>
               <script type="text/javascript" src="ClientGlobalContext.js.aspx"></script>
               <script type="text/javascript">
                   function ABC() {
                       debugger;
                       var form = document.forms[0];
                       var context = GetGlobalContext();
                       var attrVal = window.parent.document.crmForm.<Attribute Name>.value;
                          //******************************************                                  //********* your Custom Code **********************
              //******************************************
                           }
       </script>
<meta charset="utf-8"> 
  <body onload="ABC()">  
   <form method="post" action="">
    //******************************************
    //********* your HTML **********************
    //******************************************
    </form>
  </body>   
</html>

Enjoy the great technology Dynamics CRM. Good luck.....!!!!! 
Post a Comment