|
При нажатии кнопки Позвонить происходит вызов на внутренний номер звонящего (для того чтобы он поднял трубку), далее на номер вызываемого абонента.
Приведенный в руководстве скрипт, разрабатывался и тестировался для MS CRM 4.0 и 3CX v.7
Для хранения внутреннего номера используется поле Основной телефон (имя схемы address1_telephone1), сущность Пользователь.

Для сущности Контакт необходимо создать кнопку Позвонить.
Создайте атрибут Call (имя схемы new_button, тип текст), для сущности Контакт.

Добавьте поле Call на форму Контакт.

Добавьте скрипт на событие OnLoad.

//Определение внутреннего номера пользователя CRM
function GetUserExt()
{
var XMLRequest = "" +
"<?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>" +
" <RetrieveMultiple xmlns=\"http://schemas.microsoft.com/crm/2007/WebServices\">" +
" <query xmlns:q1=\"http://schemas.microsoft.com/crm/2006/Query\" xsi:type=\"q1:QueryExpression\">" +
" <q1:EntityName>systemuser</q1:EntityName>" +
" <q1:ColumnSet xsi:type=\"q1:ColumnSet\">" +
" <q1:Attributes>" +
" <q1:Attribute>systemuserid</q1:Attribute>" +
" <q1:Attribute>fullname</q1:Attribute>" +
" <q1:Attribute>address1_telephone1</q1:Attribute>" +
" </q1:Attributes>" +
" </q1:ColumnSet>" +
" <q1:Distinct>false</q1:Distinct>" +
" <q1:Criteria>" +
" <q1:FilterOperator>And</q1:FilterOperator>" +
" <q1:Conditions>" +
" <q1:Condition>" +
" <q1:AttributeName>systemuserid</q1:AttributeName>" +
" <q1:Operator>EqualUserId</q1:Operator>" +
" </q1:Condition>" +
" </q1:Conditions>" +
" </q1:Criteria>" +
" </query>" +
" </RetrieveMultiple>" +
" </soap:Body>" +
"</soap:Envelope>" +
"";
try
{
var xmlHttpRequest = new ActiveXObject("Msxml2.XMLHTTP");
xmlHttpRequest.Open("POST", "/mscrmservices/2007/CrmService.asmx", false);
xmlHttpRequest.setRequestHeader("SOAPAction","http://schemas.microsoft.com/crm/2007/WebServices
/RetrieveMultiple");
xmlHttpRequest.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
xmlHttpRequest.setRequestHeader("Content-Length", XMLRequest.length);
xmlHttpRequest.send(XMLRequest);
var Result = xmlHttpRequest.responseXML;
var BusinessEntityNodes = Result.selectNodes("//RetrieveMultipleResult/BusinessEntities/BusinessEntity");
if (BusinessEntityNodes.length != 0)
{
var BusinessEntityNode = BusinessEntityNodes[0];
var SystemUserId = BusinessEntityNode.selectSingleNode("q1:systemuserid");
var FullName = BusinessEntityNode.selectSingleNode("q1:fullname");
var Extension = BusinessEntityNode.selectSingleNode("q1:address1_telephone1");
var SystemUserId = (SystemUserId == null) ? null : SystemUserId.text;
var FullName = (FullName == null) ? null : FullName.text;
var Extension = (Extension == null) ? null : Extension.text;
}
return Extension;
}
catch (e)
{
alert(e.message);
}
}
alert(GetUserExt());
var ext = GetUserExt();
// Скрипт для создание кнопки
crmForm.all.new_button.DataValue = "Позвонить";
crmForm.all.new_button.style.textAlign = "center";
crmForm.all.new_button.vAlign = "middle";
//we make the mouse look as a hand when we're moving over
crmForm.all.new_button.style.cursor = "hand";
crmForm.all.new_button.style.backgroundColor = "#CADFFC";
crmForm.all.new_button.style.color = "#FF0000";
crmForm.all.new_button.style.borderColor = "#330066";
crmForm.all.new_button.style.fontWeight = "bold";
crmForm.all.new_button.contentEditable = false;
crmForm.all.new_button.attachEvent("onmousedown",color1);
crmForm.all.new_button.attachEvent("onmouseup",color2);
crmForm.all.new_button.attachEvent("onmouseover",color3);
crmForm.all.new_button.attachEvent("onmouseleave",color4);
function color3() {
crmForm.all.new_button.style.backgroundColor = "#6699FF";
}
function color4() {
crmForm.all.new_button.style.backgroundColor = "CADFFC";
}
function color1() {
crmForm.all.new_button.style.color = "000099";
}
function color2() {
crmForm.all.new_button.style.color = "FF0000";
}
crmForm.all.new_button.attachEvent("onclick",call);
//Функция вызова
function call() {
var to=crmForm.all.telephone1.DataValue;
var url = "http://192.168.0.2:5484/PbxAPI.aspx?func=make_call&from=" + ext + "&pin=" + ext + "&to=" + to;
alert(url);
call_window=window.open(url)
call_window.close();
}
192.168.0.2 - необходимо заменить на адрес 3CX-сервера. Скрипт работает при условии ПИН = Внутреннему Номеру.
Результат в форме контакта.

|