Monday, 28 October 2013

How to Call a HTML web resource from a Java script

Create  a Java script 

function showstatus()
{
   
alert("hi hw r u");
 var WinSettings = "center:yes;resizable:no;dialogHeight:300px;dialogWidth:650px";
window.showModalDialog("../WebResources/new_show.html", null, WinSettings);

}

Create a HTML web resource with name show.html :
In Html web resource we can call any entity using soap or o data query .

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><html><head><meta charset="utf-8"></head><body onload="getAllData();"> 
  
   <title>CRM 2011 HTML Web Resource </title> 
   <!-- including the 'ClientGlobalContext.js.asp'      -- which gives the context information--> 
   <script src="ClientGlobalContext.js.aspx">     </script>   
  <!-- including the minified version of jquery-->   
 <!--script type="text/javascript" src="new_jquery_1.4.1.min.js"--> 
    <script language="javascript">       
 function getAllData()
 {             var serverUrl;           
 var ODataPath;            
var userid;            
var userRole;         
   var OrgName;        
    var context = GetGlobalContext();          
  serverUrl = context.getServerUrl();           
 ODataPath = serverUrl + "/XRMServices/2011/OrganizationData.svc";  
          userid = context.getUserId();            
   userRole = context.getUserRoles();         
   OrgName = context.getOrgUniqueName();     
       Text1.Title = serverUrl;          
  Text2.Title = userid;            
Text3.Title = userRole;           
 Text4.Title = OrgName;          
  Text1.value = serverUrl;         
   Text2.value = userid;          
  Text3.value = userRole;         
   Text4.value = OrgName;       
 }   
 </script>
  
   
 <p>ServerURL:&nbsp;        
<input id="Text1" type="text"></p>  
  <p>User ID &nbsp;      
  <input id="Text2" type="text"></p>   
 <p>User Role &nbsp;       
 <input id="Text3" type="text"></p> 
   <p>Oraganization &nbsp;         
<input id="Text4" type="text"></p>

</body></html>

One can also update any entity using java script:
In Account form invoking a Html webpage and taking input from user and updating in CRM

var WinSettings = "center:yes;resizable:no;dialogHeight:300px;dialogWidth:650px"
    var clientInformation = window.showModalDialog("../WebResources/lbg_Contact_Client_Address", GuidArgs, WinSettings);
 
    Xrm.Page.getAttribute('address1_line1').setValue(clientInformation[0]);
    Xrm.Page.getAttribute('address1_line2').setValue(clientInformation[1]);
    Xrm.Page.getAttribute('address1_line3').setValue(clientInformation[2]);
    Xrm.Page.getAttribute('address1_city').setValue(clientInformation[3]);
    Xrm.Page.getAttribute('address1_county').setValue(clientInformation[4]);
    Xrm.Page.getAttribute('address1_postalcode').setValue(clientInformation[5]);
    Xrm.Page.getAttribute('address1_country').setValue(clientInformation[6]);