While working on a requirement a need arise to display a field in the LookUp display which is not a PrimaryNameField.
Let\’s consider the Order Lookup field here on Case Form.
Requirement :
Display OrderNo in the display field instead of the OrderName (Which is a PrimaryNameField) in every Order Lookup.
(I have implemented this requirement in CRM 2015)
Javascript :
Pass Lookup Field as Parameter (I had passed \”new_orderno\” as fieldname parameter)
//Change Lookup Display Text
function ChangeLookUpDisplayValue(fieldname)
{
var lookupData = new Array();
var lookupItem= new Object();
var lookup = Xrm.Page.data.entity.attributes.get(fieldname);
if(lookup!=null)
{
var displayvalue=\’\’;
var xmlText=\’\’;
xmlText+=\”\”;xmlText+=\”\”;
xmlText+=\”\”;
xmlText+=\”salesorder\”;
xmlText+=\”\”+lookup.getValue()[0].id+\”\”;
xmlText+=\”\”;
xmlText+=\”false\”;
xmlText+=\”\”;
xmlText+=\”ordernumber\”;
xmlText+=\”\”;
xmlText+=\”\”;
xmlText+=\”\”;
xmlText+=\”\”;
xmlText+=\”\”;
var xHReq = new XMLHttpRequest();
var url=Xrm.Page.context.getClientUrl()+\”/XRMServices/2011/Organization.svc/web\”;
xHReq.open(\”POST\”,url,false);
xHReq.setRequestHeader(\”SOAPAction\”,\”http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Retrieve\”);
xHReq.setRequestHeader(\”Content-Type\”, \”text/xml; charset=utf-8\”);
xHReq.setRequestHeader(\”Accept\”,\”application/xml,text/xml,*/*\”);
xHReq.send(xmlText);
//Capture the result.
var resultXml = xHReq.responseXML;
var varray = new Array();
//Check for errors.
var errorCount = resultXml.selectNodes(\’//s:Fault\’).length;
if(errorCount != 0)
{
var msg = resultXml.selectSingleNode(\’//faultstring\’).nodeTypedValue;
alert(msg);
}
else
{
var result = resultXml.getElementsByTagName(\”a:KeyValuePairOfstringanyType\”);
if(result.length>0)
{
displayvalue= result[0].childNodes[1].lastChild.text;
}
if(displayvalue!=\’\’)
{
lookupItem.name = displayvalue;
lookupData[0] = lookupItem;
lookup.DataValue = lookupData;
Xrm.Page.getAttribute(\”new_orderno\”).setValue([{id:lookup.getValue()[0].id,name:displayvalue,entityType:\”salesorder\”}]);
}
}
}
}
After Putting Above Javascript Lookup display text will look like below :
if the form is saved the display text of lookup automatically changed into old
LikeLike
Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time. Contact him now and thank me later.
LikeLike
Special thanks to (hackingsetting50@gmail.com) for exposing my cheating husband. Right with me i got a lot of evidences and proofs that shows that my husband is a fuck boy and as well a cheater ranging from his text messages, call logs, whats-app messages, deleted messages and many more, All thanks to (hackingsetting50@gmail.com), if not for him i will never know what has been going on for a long time. Contact him now and thank me later.
LikeLike