Цитата:
Сообщение от
O_Chiner
Будьте добры!
Вот такой код:
Код:
function GetBUId(userid)
{
if (userid == null)
return null;
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("POST", "/mscrmservices/2007/crmservice.asmx", false);
xmlhttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlhttp.setRequestHeader("SOAPAction", "http://schemas.microsoft.com/crm/2007/WebServices/Fetch");
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'>"+
GenerateAuthenticationHeader() +
" <soap:Body>" +
"<Fetch xmlns='http://schemas.microsoft.com/crm/2007/WebServices'>"+
"<fetchXml> "+
"<fetch mapping='logical'> " +
"<entity name='systemuser'> " +
"<attribute name='businessunitid' /> " +
"<filter type='and'> " +
"<condition attribute='systemuserid' operator='eq' value='" + userid +"'/> " +
"</filter> " +
"</entity> " +
"</fetch>"+
"</fetchXml>"+
"</Fetch>"+
"</soap:Body>"+
"</soap:Envelope>";
xmlhttp.setRequestHeader("Content-Length", xml.length);
xmlhttp.send(xml);
var resultSet = new String(xmlhttp.responseXml.text);
resultSet.replace('<','<');
resultSet.replace('>','>');
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.loadXML(resultSet);
var lookupitem = new Object();
lookupitem.typename = "businessunit";
lookupitem.id = xmlDoc.selectSingleNode("//resultset/result/businessunitid").nodeValue;
lookupitem.name = xmlDoc.selectSingleNode("//resultset/result/businessunitid").attributes.getNamedItem("name").text;
retutn lookupItem;
}
if (crmForm.all.ownerid.DataValue != null
&& crmForm.all.ownerid.DataValue.length != 0
&& crmForm.all.ownerid[0] != null)
{
var lookupData = new Array();
lookupData[0] = GetBUId(crmForm.all.ownerid[0].id);
crmForm.all.new_businessunitid.DataValue = lookupData;
}
Чтобы не забыть напишу, что у пользователя должны быть права на Assign To к сущности BusinessUnit иначе даже такое присвоение никакого результата не даст. Уже сталкивался. Удачи.