Documentation

Create Activities via Apps

Application can create activities with a special type of provider. Such activities will have a corresponding icon and will be displayed within a timeline. When such activity is clicked, it opens the app in slider with options specified in PLACEMENT_OPTIONS.

Parameters

Method Description
PROVIDER_ID Provider identifier. Must be set as 'REST_APP' for the special provider.
PROVIDER_TYPE_ID Activity type ID. Developer can specify arbitrary identifiers for the type when using the 'REST_APP' provider, depending on developer objectives.

Example

<?php
header('Content-Type: text/html; charset=UTF-8');
?>
<!DOCTYPE html>
<html>
<
	<meta charset="UTF-8">
	<title>
	<style type="text/css">

	</style>
</head>
<body style="display: none">
<script src="//api.bitrix24.com/api/v1/"></script>

<?if (isset($_POST['PLACEMENT']) && !empty($_POST['PLACEMENT_OPTIONS'])):
	$opt = json_decode($_POST['PLACEMENT_OPTIONS'], true);
?>
<p>Activity ID: <?=(int)$opt['activity_id']?></p>
<button oncl ick="updateActivity(<?=(int)$opt['activity_id']?>);">Upd ate activity (se t new description + completed)
<p><button oncl ick="deleteActivity(<?=(int)$opt['activity_id']?>);">delete activity</button>
<?else:?>
<button oncl ick="selectCRMEntity();">Select LEAD</button>
<span id="selected-entity"></span>
<p>
<button oncl ick="addActivity();">Add activity</button>
<?endif;?>
<script type="text/javascript">
	BX24.init(function()
	{
		document.body.style.display = '';
	});

	var selectedEntityId = null;

	function addActivity()
	{

		if (!selectedEntityId)
		{
			alert('Lead not selected');
			return;
		}
		BX24.callMethod(
			'crm.activity.add',
			{
				fields:
					{
						"OWNER_TYPE_ID": 1,
						"OWNER_ID": selectedEntityId,
						"PROVIDER_ID": 'REST_APP',
						"PROVIDER_TYPE_ID": 'LINK',
						"SUBJECT": "New activity",
						"COMPLETED": "N",
						"RESPONSIBLE_ID": 1,
						"DESCRIPTION": "New activity description"
					}
			},
			function(result)
			{
				if(result.error())
					alert("Error: " + result.error());
				else
				{
					alert("Success: " + result.data());
				}
			}
		);
	}
	function updateActivity(id)
	{
		BX24.callMethod(
			'crm.activity.update',
			{
				id: id,
				fields:
					{
						COMPLETED: 'Y',
						SUBJECT: "Activity complete!",
						DESCRIPTION: "New activity description (completed)"
					}
			},
			function(result)
			{
				if(result.error())
					alert("Error: " + result.error());
				else
				{
					alert("Success: " + result.data());
				}
			}
		);
	}

	function deleteActivity(id)
	{
		BX24.callMethod(
			'crm.activity.delete',
			{
				id: id
			},
			function(result)
			{
				if(result.error())
					alert("Error: " + result.error());
				else
				{
					alert("Success: " + result.data());
				}
			}
		);
	}

	function selectCRMEntity()
	{
		document.getElementById('selected-entity').textContent = '';
		BX24.selectCRM({
			entityType: ['lead']
		}, function(selected)
		{
			if (selected['lead'] && selected['lead'][0])
			{
				document.getElementById('selected-entity').textContent = selected['lead'][0]['title'];
				var	id =  selected['lead'][0]['id'];

				selectedEntityId = id.substring(2);

				console.log(selectedEntityId);
			}
		})
	}
</script>
</body>
</html>


User Comments

User comments are not part of official documentation. Use information provided by other users in the comments at your own risk.

The User Comments section is not to be used as a feature discussion board. Only registered users can post comments. Your comment will be visible once it has been approved by the moderator.
© «Bitrix Inc.», 2001-2021, «Bitrix Inc.», 2021