Otra opción distinta a la del post Cambiar el Valor que muestra un Lookup.

En el Evento OnLoad del Formulario, colocar siguiente Jscript en el evento onLoad (Update) y en el Onchange del atributo. Modificar:

  • new_id: Nombre del Campo Lookup
  • entityName: Entidad a la cual se realiza Lookup
  • otherName: Nombre a mostrar que va a reemplazar el que se muestra por defecto

Codigo:

if(crmForm.all.new_id.DataValue!=null)
{
var lookupItem1 = new Array;
lookupItem1 = crmForm.all.new_id.DataValue;
var id = lookupItem1[0].id;
var authenticationHeader = GenerateAuthenticationHeader();
// Prepare the SOAP message.
var xml = "<?xml version=’1.0′ encoding=’utf-8′?>"+
"<soap:Envelope xmlns:soap=’http://schemas.xmlsoap.org/soap/envelope/‘"+
" xmlns:xsi=’http://www.w3.org/2001/XMLSchema-instance‘"+
" xmlns:xsd=’http://www.w3.org/2001/XMLSchema‘>"+
authenticationHeader+
"<soap:Body>"+
"<Retrieve xmlns=’http://schemas.microsoft.com/crm/2007/WebServices‘>"+
"<entityName>entityName</entityName>"+
"<id>"+id+"</id>"+
"<columnSet xmlns:q1=’http://schemas.microsoft.com/crm/2006/Query‘ xsi:type=’q1:ColumnSet’>"+
"<q1:Attributes>"+
"<q1:Attribute>otherName</q1:Attribute>"+
"</q1:Attributes>"+
"</columnSet>"+
"</Retrieve>"+
"</soap:Body>"+
"</soap:Envelope>";
// Prepare the xmlHttpObject and send the request.
var xHReq = new ActiveXObject("Msxml2.XMLHTTP");
xHReq.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xHReq.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices/Retrieve");
xHReq.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xHReq.setRequestHeader("Content-Length", xml.length);
xHReq.send(xml);
// Capture the result.
var resultXml = xHReq.responseXML;
// Check for errors.
var errorCount = resultXml.selectNodes(‘//error’).length;
if (errorCount != 0)
{
var msg = resultXml.selectSingleNode(‘//description’).nodeTypedValue;
alert(msg);
}
// Display the retrieved value.
else
{
var lookupData = new Array();
var lookupItem= new Object();
lookupItem.id = id;
lookupItem.typename = ‘entityName’;
lookupItem.name = resultXml.selectSingleNode("//q1:otherName").nodeTypedValue;
lookupData[0] = lookupItem;
crmForm.all.new_id.DataValue = lookupData;
}
}

Nuevo_Logo