Skip to main content

How to add a custom activity type in Bitrix24 CRM

During one of our recent self-hosted Bitrix24 implementations, we had the task of adding a new type of Activity to CRM - something between a Call Activity and a Visit Activity. The customer wanted this new Activity to be able to participate in CRM reports and filters.

To begin with, it was necessary to add a link to a new Activity type in the CRM entity card.



We found out that the crm.timeline component is responsible for the output of this part of the interface. In particular, its template.php contains a list of displayed links to case types. For example, for a call, something like:



Accordingly, as we can see, this is a regular link with the data parameter item-item-id. So we can add ours, with our own unique data-item-id.

As you can see, the href for the link is set as "#" - clicking on this link is processed by the JS code from the script.js of this component. Indeed, the BX.CrmTimelineMenuBar function is responsible for this.processItemSelection(). Here is the code that handles the click of a link for the Call case:



Here, the very parameter from data-item-id is checked. Also, using BX.Crm.Activity.Planner, a form for adding a new case is called. It will need to pass the TYPE_ID of the Activity provider and information about the current CRM entity in the OWNER_TYPE_ID and OWNER_ID fields.

We can completely copy the call for the Call, replacing only our data-item-id. After that, a link to our custom Activity type will appear in the interface of the card, and when you click on it, a call creation form will open.

Now it's time to figure out how to register your own type of Activity.

Having studied the available documentation, we can see that this can be done by subscribing to the CRM module's OnGetActivityProviders event and returning a special class that describes the provider type of case inherited from \Bitrix\Crm\Activity\Provider\Base



You can also navigate here to the existing providers of Activity types. They can be found along the path: /bitrix/modules/crm/lib/activity/provider.

You can focus on the visit.php example as the most basic. The code of these providers is clear enough. In the simplest case, you only need to specify the getName() and getTypes() functions. The getTypes() function just describes the types of Activity:



The values ​​PROVIDER_ID and PROVIDER_TYPE_ID must be unique; we will need them further. In our case, we specified YBWS_QUOTATION in both fields.

The Activity type is ready, registered, and has already appeared in the Activity filter:



As you remember, when we clicked on the type of Activity in the CRM card, a Call form was called up. Now we can call up the form of our own Activity:



As you see in TYPE_ID we specified BX.Crm.Activity.Planner, and in PROVIDER_ID and PROVIDER_TYPE_ID we specified YBWS_QUOTATION. Now, when you click on our type of Activity, its own form opens. The appearance of this form can be changed using the renderView function of our Activity provider class.

In order for our type of Activity to appear in the button for creating new activities in the to-do list, you need to add the prepareToolbarButtons function of the Activity provider.



In order for statistics to be collected by type of Activity and be used in CRM reports, you need to specify the following in the getSupportedCommunicationStatistics() function:



Now you can build charts for your types of Activity:



You can also build reports using custom Activity types:


Comments

  1. This comment has been removed by a blog administrator.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete

Post a Comment

Popular posts from this blog

How to setup server for Bitrix24 on AWS EC2

How to сreate AWS Lambda Layer with Zeep Library

Python Zeep library designed to work with SOAP - services. Zeep is a pure-python module. However the lxml dependency does contain C code since it uses libxml2 and libxslt. So the Zeep library can not be deployed into the Lambda Layer without some tricks. In one of my Serverless projects, I needed to use this library, and I found such a way to deploy it into the Layer: