Ставил этот скрипт на поле ownerid, событие onChange:
X++:
var ownerLookupItem = new Array;
ownerLookupItem = crmForm.all.ownerid.DataValue;
var lookupData = new Array();
var bUnitLookupItem= new Object();
if (ownerLookupItem != null)
{
if (ownerLookupItem[0] != null)
{
var oXmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
sGUID=ownerLookupItem[0].id;
if (sGUID != null)
{
var sEntityName="systemuser";
var sAttributeName="businessunitid";
var bUID ="";
bUID = GetAttributeValue(sEntityName, sGUID, sAttributeName);
var bUEntityName ="businessunit";
var bUEntityType ="name";
var bUName = GetAttributeValue(bUEntityName, bUID, bUEntityType);
bUnitLookupItem.id = bUID;
bUnitLookupItem.typename = bUEntityName;
bUnitLookupItem.name = bUName;
lookupData[0] = bUnitLookupItem;
crmForm.all.new_businessunit_incident.DataValue = lookupData;
}
}
}
function GetAttributeValue(sEntityName, sGUID, sAttributeName)
{
var xml = "";
xml +="<?xml version=\"1.0\" encoding=\"utf-8\"?>";
xml +="<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\">";
xml += GenerateAuthenticationHeader();
xml +="<soap:Body>";
xml +="<entityName xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sEntityName + "</entityName>";
xml +="<id xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\">" + sGUID + "</id>";
xml +="<columnSet xmlns=\"http://schemas.microsoft.com/crm/2006/WebServices\" xmlns:q=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q:ColumnSet\">";
xml +="<q:Attributes>";
xml +="<q:Attribute>" + sAttributeName + "</q:Attribute>";
xml +="</q:Attributes>";
xml +="</columnSet>";
xml +="</soap:Body>";
xml +="</soap:Envelope>";
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2006/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2006/WebServices/Retrieve");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", xml.length);
xmlHttpRequest.send(xml);
var doc = xmlHttpRequest.responseXML;
var retValue = "";
if (doc.selectSingleNode("//RetrieveResult/q1:" + sAttributeName) != null)
retValue = doc.selectSingleNode("//RetrieveResult/q1:" + sAttributeName).text;
return retValue;
}