Some clients like to have other text shown on the lookup fields, that’s the example on the Originating Lead field that links a Lead to an Opportunity (and Accounts and Contacts), because the lookup field in the Opportunity shows the Contact name (if the contact field is filled in the Lead), if not, then the lookup field appears to be empty.
So this is a code that will allow you to change the text to anything that you want/need. In our case it was the name of the Lead (subject field).
function ChangeLookUpDisplayValue()
{
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);
}
}
}
}
}
Hope this helps.


