Recent Posts

ads

How to set lookup field using javascript in Dynamics CRM


 In Microsoft CRM such huge numbers of individuals have numerous issues with retriving information from the Lookup field . 

Presently in this post I will offer how to retrive Lookup information and set the qualities into fields. 

Here in the fundamental things is field sensible names 

, it's case delicate we will duplicate the specific sensible name and glue into the code appropriately. In Lookup field getting information we will follow slight distinction legitimate name 

$select=lvt_address,lvt_email,lvt_phone,_lvt_contactofferlookup_value"

If it's not too much trouble check it the above We are getting ordinary field without looking we use "lvt_address", " lvt_email" and so forth. Presently we will getting query field esteem is comparative yet slight contrast we use "_lvt_contactofferlookup_value". 

Presently we have araised one uncertainty as a primary concern right how we will take those intelligent field names. We don't trouble on that since framework is produced consequently when we make fields in CRM structures.

javascript



JavaScript webapi :



function RetrieveLookupRecord() { debugger; try { var offerGuid = null, nextLine = "\n"; offerGuid = Xrm.Page.getAttribute("lvt_offerlookup").getValue(); if (offerGuid != null && offerGuid != "") { Xrm.WebApi.retrieveRecord("lvt_offer", offerGuid[0].id, "$select=lvt_address,lvt_email,lvt_phone,_lvt_contactofferlookup_value") .then(function (data) { retrieveContactSuccess(data); }, function (error) { Xrm.Utility.alertDialog(error.message); }); } } catch (e) { Xrm.Utility.alertDialog(e.message); } ///retrieve success function retrieveContactSuccess(data) { try { //get the values //string var Address = data["lvt_address"]; var Email = data["lvt_email"]; var Phone = data["lvt_phone"]; var retrivedvalue = data["_lvt_contactofferlookup_value"]; var retrivedvalueformatted = data["_lvt_contactofferlookup_value@OData.Community.Display.V1.FormattedValue"]; var retrivedvalueentityType = data["_lvt_contactofferlookup_value@Microsoft.Dynamics.CRM.lookuplogicalname"]; if (retrivedvalue != null) { var value = new Array(); value[0] = new Object(); value[0].id = retrivedvalue; value[0].name = retrivedvalueformatted; value[0].entityType = retrivedvalueentityType; } Xrm.Page.getAttribute('lvt_address').setValue(Address); Xrm.Page.getAttribute('lvt_email').setValue(Email); Xrm.Page.getAttribute('lvt_phone').setValue(Phone); Xrm.Page.getAttribute("lvt_contactlookup").setValue(value); } catch (e) { Xrm.Utility.alertDialog(e.message); } } }











Post a Comment

0 Comments