0

I'd like to add a new field to lead form.
Is it possible to be done?

arra('name' => 'PROJECT',
    'title' => Loc::getMessage('CRM_LEAD_FIELD_PROJECT'),
    'type' => 'list',
    'editable' => true,
    // 'entityTypeName' => CCrmOwnerType::project,
    'data' => array(
                'items'=>\CCrmInstantEditorHelper::PrepareListOptions(
                CallProject::GetListCrm('PROJECT'),
                array('NOT_SELECTED' =>                                                                      Loc::getMessage('CRM_LEAD_PROJECT_NOT_SELECTED')))
    )

),
Azametzin
  • 5,223
  • 12
  • 28
  • 46
Praful
  • 15
  • 1
  • 3

1 Answers1

0

You can find most Bitrix processes by using XDebug and performing the actions in the interface. In the case of adding a field to a lead form, that happens in ajax.php of the crm.config.fields.edit component.

Here's my version of it:

global $USER_FIELD_MANAGER;
CModule::IncludeModule('crm');

$entityID = "CRM_LEAD";
$crmFields = new CCrmFields($USER_FIELD_MANAGER, $entityID);
$fieldName = $crmFields->GetNextFieldId();

$label = "nameOfTheNewField";

$languageCodes = ["de", "en", "la", "br", "lt"];

$editFormLabel = [];
$listColumnLabel = [];
$listFilterLabel = [];

foreach($languageCodes as $languageCode) {
    $editFormLabel[$languageCode] = $label;
    $listColumnLabel[$languageCode] = $label;
    $listFilterLabel[$languageCode] = $label;
}
// can be 'string', 'integer', 'double', 'boolean', 'datetime', according to the ajax.php
$dataType = "string";

$fields = [
  "USER_TYPE_ID"=> $dataType,
  "ENTITY_ID"=> $entityID,
  "SORT"=> 100,
  "MULTIPLE"=> "N", // Declares that you can add more, e.g. a list of strings
  "MANDATORY"=> "N", // Declares whether the form can be submitted without this value
  "SHOW_FILTER"=> "E", // Not sure
  "SHOW_IN_LIST"=> "Y", // Not sure, maybe the list at the lead overview?
  "SETTINGS"=> [],
  "EDIT_FORM_LABEL"=> $editFormLabel,
  "LIST_COLUMN_LABEL"=> $listColumnLabel,
  "LIST_FILTER_LABEL"=> $listFilterLabel,
  "FIELD_NAME"=> $fieldName
];

$fieldID = (new CUserTypeEntity())->Add($fields);

The function may take other types than suggested in that ajax.php - You can check which should be valid by inspecting the output of $USER_FIELD_MANAGER->GetUserType();.
Although I'm not sure if the leads form and the list can work with other datatypes than those listed, so you may need to adapt the component template.

CGundlach
  • 671
  • 4
  • 13