Thursday 15 October 2015

Retrieve the field value from one entity using another entity page.

Retrieve the field value from one entity using another entity page.

Hi everyone here I explain how to get a value of a field of another form using GUID.

Here I have a contact lookup in account Form. Based on that selected contact GUID I wanna get credit limit value. For that follow these steps.


Step 1:First try to get ContactId
var ContactId = Xrm.Page.getAttribute("contactname").getValue()[0].id;

Step 2: Go to Advance Finder and Give your custom logic and download fetchXML

<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>
  <entity name='contact'>
    <attribute name='contactid' />
      <filter type='and'>
      <condition attribute='contactid' operator='eq' value='+ContactId+' />
      <condition attribute='creditlimit'>
    </filter>
  </entity>
</fetch>

Step 3: Get the result and check the value of Credit Limit

var Results = XrmServiceToolkit.Soap.Fetch(FetchXml);
var CreditLimit = Results[0].attributes["creditlimit"].value;

So Finally your code is like this


function getContactId() {
    var ContactId = Xrm.Page.getAttribute("contactname").getValue()[0].id;
    var FetchXml = "<fetch version='1.0' output-format='xml-platform' mapping='logical' distinct='false'>" +
  "<entity name='contact'>" +
    "<attribute name='creditlimit' />" +
      "<filter type='and'>" +
      "<condition attribute='contactid' operator='eq' value='" + ContactId + "' />" +
       "</filter>" +
  "</entity>" +
"</fetch>"
    var Results = XrmServiceToolkit.Soap.Fetch(FetchXml);
    if (Results.length > 0) {
        if (Results[0] != null) {
            var CreditLimit = Results[0].attributes["creditlimit"].value;
            //Write your custom logic here
            }
        }
    }
}