How to get lookup value CRM 2015 using javascript

1:27 AM

You can retrieve data entity crm by sdk CRM using c# code. beside that, also you can retrieve entity in client side by javascript. these are the steps !

Step 1
Create Javascript Functon as below:

function personalautofill()
{
 var formtype =Xrm.Page.ui.getFormType();
 
 if (formtype==1){
 
  var objlookup = Xrm.Page.getAttribute("new_personal").getValue();
  if (objlookup!=null)
  {
   var personalid = objlookup[0].id;
   var personalname = objlookup[0].name;
   
   var fetchXmlPersonal = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>"+
        "<entity name='contact'>"+
       "<attribute name='fullname' />"+
       "<attribute name='telephone1' />"+
       "<attribute name='contactid' />"+
       "<attribute name='emailaddress1' />"+
       "<attribute name='mobilephone' />"+
       "<order attribute='fullname' descending='false' />"+
       "<filter type='and'>"+
         "<condition attribute='contactid' operator='eq' value='"+personalid+"' />"+
         "<condition attribute='statecode' operator='eq' value='0' />"+
       "</filter>"+
        "</entity>"+
      "</fetch>";
   var _personal = XrmServiceToolkit.Soap.Fetch(fetchXmlPersonal);
   if (_personal.length > 0){
    alert(JSON.stringify(_personal));     
   }    
  }
 }
}

Step 2
Load Javascript file and call the function
How to get lookup value CRM 2015 using javascript
How to get lookup value CRM 2015 using javascript - load js

Step 3
Result should be :
How to get lookup value CRM 2015 using javascript
How to get lookup value CRM 2015 using javascript - result
Thanks for visiting

You Might Also Like

0 comments