Monday 10 July 2017

Change Lookup Text of Originating Lead field using JavaScript and FetchXML in Dynamic CRM.

Change Lookup Text of Originating Lead field using JavaScript and FetchXML in Dynamic CRM.

Description:
In this example we explain that how to change Lookup Text of the Originating Lead field in Dynamic CRM using JavaScript and FetchXML. Or how to change the Lookup Text in dynamic CRM programmatically using JavaScript. Or how to get and set the Lookup text of the originating Lead entity field in dynamic CRM using JavaScript and FetchXML.

By default in Dynamic CRM Lookup field shows the contact name so below is the code that will allow you to change the Lookup text of the originating lead and set value of anything that you want to the Lead originating field.
Code:

function ChangeLookUpDisplayTextandValue()
{
 var lookupData = new Array();
 var lookupItem= new Object();
  
 if(Xrm.Page.getAttribute("originatingleadid") != null)
 {
   var lookup = Xrm.Page.getAttribute("originatingleadid").getValue();
  
   if (lookup != null)
   {
     lookupItem.id = lookup[0].id;
     lookupItem.typename = lookup[0].typename;
     var displayvalue='';
  
     var fetchXml =
       "<fetch mapping='logical'>" +
        "<entity name='lead'>" +
         "<attribute name='subject'/>" +
        "<filter>" +
         "<condition attribute='leadid' operator='eq' value='" + lookupItem.id + "' />" +
        "</filter>" +
        "</entity>" +
       "</fetch>";

     var retrievedLead = XrmServiceToolkit.Soap.Fetch(fetchXml);
  
     if(retrievedLead != null)
     {
       if (retrievedLead.length == 1)
       {
          displayvalue = retrievedLead[0].attributes['subject'].value;
          lookupItem.name = displayvalue;
          lookupData[0] = lookupItem;
  
          Xrm.Page.getAttribute("originatingleadid").setValue(lookupData);
       }
     }
   }
  }
 }



0 comments:

Post a Comment