S
S
Sergey Ch2017-08-01 08:27:02
1C-Bitrix
Sergey Ch, 2017-08-01 08:27:02

Group change of responsible person from a deal in a contact and a company in Bitrix CRM, boxed version?

As I understand it, when assigning a responsible JS script sends parameters via AJAX
rows[0]:17031 - deal number
rows[1]:17030 - deal number
controls[action_button_CRM_DEAL_LIST_V12]:assign_to - action name
controls[ACTION_ASSIGNED_BY_SEARCH]: full name - full name of the responsible
controls[ ACTION_ASSIGNED_BY_ID]: 34 - id responsible in the system the
POST http: // address ? site / crm / deal / list / sessid = ca344242967f7de9beefa7e4675b3cd0 & internal = true & grid_id = CRM_DEAL_LIST_V12 & grid_action = showpage & bxajaxid = a6527cffb462017dbf0dfa6a0e34cee3
I can not understand what file php is responsible not mediocre handling of these parameters and change responsible
I looked through the PHP files - bitrix/www/bitrix/components/bitrix/crm.deal.list - in search of the method necessary for modification, but did not find anything similar.
I also checked the JS scripts bitrix/www/bitrix/components/bitrix/main.ui.grid/templates/.default

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikolaev, 2017-08-01
@elov4anin

You correctly found that the bitrix:crm.deal.list component is responsible for this, which is located in /bitrix/components/bitrix/crm.deal.list/component.php.
The code is a bit confusing, but it works like this:
At ~614 time ( ~ 614 - 679 ) there is a code that parses the received data and collects it in the $actionData array

//region Try to extract user action data
// We have to extract them before call of CGridOptions::GetFilter() or the custom filter will be corrupted.
$actionData = array(
  'METHOD' => $_SERVER['REQUEST_METHOD'],
  'ACTIVE' => false
);

if(check_bitrix_sessid())
{
  $postAction = 'action_button_'.$arResult['GRID_ID'];
  $getAction = 'action_'.$arResult['GRID_ID'];
  //We need to check grid 'controls'
  $controls = isset($_POST['controls']) && is_array($_POST['controls']) ? $_POST['controls'] : array();
  if ($actionData['METHOD'] == 'POST' && (isset($controls[$postAction]) || isset($_POST[$postAction])))
  {
    CUtil::JSPostUnescape();

    $actionData['ACTIVE'] = true;

    if(isset($controls[$postAction]))
    {
      $actionData['NAME'] = $controls[$postAction];
    }
    else
    {
      $actionData['NAME'] = $_POST[$postAction];
      unset($_POST[$postAction], $_REQUEST[$postAction]);
    }
  ...
  ...
  ...
    $actionData['AJAX_CALL'] = $arResult['IS_AJAX_CALL'];
  }
}
//endregion

And from line ~915, direct processing begins (~915 - 1457):
// POST & GET actions processing -->
if($actionData['ACTIVE'])
{
  if ($actionData['METHOD'] == 'POST')
  {
    if($actionData['NAME'] == 'delete')
    {
    ...
    elseif($actionData['NAME'] == 'assign_to')
    {
      if(isset($actionData['ASSIGNED_BY_ID']))
      {
        $arIDs = array();
        if ($actionData['ALL_ROWS'])
        {
          $arActionFilter = $arFilter;
          $arActionFilter['CHECK_PERMISSIONS'] = 'N'; // Ignore 'WRITE' permission - we will check it before update.
          $dbRes = CCrmDeal::GetListEx(array(), $arActionFilter, false, false, array('ID'));
          while($arDeal = $dbRes->Fetch())
          {
            $arIDs[] = $arDeal['ID'];
          }
        }
        elseif (isset($actionData['ID']) && is_array($actionData['ID']))
        {
          $arIDs = $actionData['ID'];
        }

        foreach($arIDs as $ID)
        {
          if (!CCrmDeal::CheckUpdatePermission($ID, $userPermissions))
          {
            continue;
          }

          $DB->StartTransaction();

          $arUpdateData = array(
            'ASSIGNED_BY_ID' => $actionData['ASSIGNED_BY_ID']
          );

          if($CCrmDeal->Update($ID, $arUpdateData, true, true, array('DISABLE_USER_FIELD_CHECK' => true)))
          {
            $DB->Commit();

            $arErrors = array();
            CCrmBizProcHelper::AutoStartWorkflows(
              CCrmOwnerType::Deal,
              $ID,
              CCrmBizProcEventType::Edit,
              $arErrors
            );
          }
          else
          {
            $DB->Rollback();
          }
        }
      }
    }
    ...
  }
}
// <-- POST & GET actions processing

But there is a small nuance, if you need to change the responsible in related entities, customizing this code will not be the best solution.
In this case, you will have doubling, for example, the responsible person can be changed through a mass change of the responsible person in the list, through editing a deal, through a business process action block, and so on. And all these are different mechanisms. They have only one thing in common - they all use events for changes / additions.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question