Answered by:
How to display the billet number in the display field instead of the BilletName

Question
-
How to display billet number in the display field instead of the BilletName(which is a PrimaryNameField) in every Billet Lookup?
My code below is not working:
function ChangeLookupDisplay() { var lookupData = new Array(); var lookupItem = new Object(); var lookup = document.getElementById("jsoc_billetnumberluf"); alert("inside function"); if (lookup != null && lookup.DataValue != null) { lookupItem.id = lookup.DataValue[0].id; lookupItem.typename = lookup.DataValue[0].typename; alert("inside first if"); alert("My field id: " + lookupItem.id); var displayvalue = ''; var xmlText = ''; xmlText += "<s:Envelope xmlns:s=\http://schems.xmlsoap.org/soap/envelope/\">"; xmlText += "s:Body>"; xmlText += "<Retrieve xlmns=\"http://schemas.microsoft.com/xrm/2011/Contracts/Service\" xmlns:i = \http:www.w3.org./2001/XMLSchema-instance\">"; xmlText += "<entityName>billetNumber</entityName>"; xmlText += "<id>" + lookup.DataValue[0].id + "</id>"; alert("<id>" + lookup.DataValue[0].id + "</id>"); xmlText += "columnSet xmlns:a=\"http://schemas.microsoft.com/xrm/2011/Contracts\">"; xmlText += "<a:AllColumns>false</a:AllColumns>"; xmlText += "<a:Columns xmlns:b=\"http://schemas.microsoft.com/2003/10/Serialization/Arrays\">"; xmlText += "<b:string>billetnumber</b:string>"; xmlText += "</a:Columns>"; xmlText += "</ColumnSet>"; xmlText += "</Retrieve>"; xmlText += "</s:Body>"; xmlText += "</s:Envelope>"; alert(xmlText); var xHReq = new XMLHttpRequest(); var url = Xrm.Page.context.getServiceUrl() + "/XRMServices/2011/Organization.svc/web"; xHReq.open("POST", url, false); xHReq.setRequestHeader("SOAPAction", "http://schemas.mircosoft.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); alert(xHReq); // Capture the result. var resultXml = xHReg.responseXML; var varray = new Array(); // Check for error. var errorCount = resultXml.selectNodes ('//s:Fault').length; if (errorCount != 0) { var msg = resultXml.selectSingleNode('//faultstring').nodeTypeValue; alert(msg); } else { var result = resultXml.getElementsByTagName("a:KeyValuePairOfstringanyType"); if (result.length > 0) { displayvalue = result[0].childNodes[1].lastChild.text; } if (displayvalue != '') { lookupData.name = displayvalue; lookupData[0] = lookupItem; lookup.DataValue = lookupData; } } } }
Tuesday, May 14, 2013 3:41 PM
Answers
-
If you do not use the name field (the primary field), instead of using these code, try to use a workflow. Workflow should be triggered on the create of the entity, then update it with desired values (Billet number). This causes the lookup field on the other entities appears as Billet number.
- Proposed as answer by Payman BiukaghazadehEditor Tuesday, May 14, 2013 3:56 PM
- Marked as answer by Payman BiukaghazadehEditor Tuesday, May 14, 2013 4:50 PM
Tuesday, May 14, 2013 3:56 PMModerator
All replies
-
If you do not use the name field (the primary field), instead of using these code, try to use a workflow. Workflow should be triggered on the create of the entity, then update it with desired values (Billet number). This causes the lookup field on the other entities appears as Billet number.
- Proposed as answer by Payman BiukaghazadehEditor Tuesday, May 14, 2013 3:56 PM
- Marked as answer by Payman BiukaghazadehEditor Tuesday, May 14, 2013 4:50 PM
Tuesday, May 14, 2013 3:56 PMModerator -
Ok, is there any examples of how to do this, I'm very new to CRM only been working with it a few weeks.Tuesday, May 14, 2013 4:43 PM
-
Tuesday, May 14, 2013 4:50 PMModerator