catalog.documentcontractor.add
Scope: catalog Permissions to execute: for all
catalog.documentcontractor.add(fields)
Method adds (Contact/Company) CRM entity binding to an inventory object/document.
Response returns list of binding fields, as in method getFields. The list returns binding ID for further handling of the binding.
The cases of returned errors when adding an association/binding to inventory object/document:
- where there's no access to inventory management, no access to view stock receipts or no access to edit stock receipt (binding adding/deleting is also deemed as editing action);
- inventory object/document not found;
- inventory object/document incorrect type (binding to vendors is applicable only for Stock receipt inventory objects);
- if no inventory object/document was processed (cannot edit an inventory object/document after it was processed);
- incorrect entity type (the field entityTypeId receives only values 3 or 4);
- on attempting to bind vendor/supplier Company to a stock receipt, when this inventory object/document has already associated vendor Company (it's permitted to bind several Contacts, but not more than a single Company).
Parameters
Parameter | Type | Description |
---|---|---|
fields | object | Fields documentId, entityTypeId и entityId, corresponding to the available list of fields. |
Examples
BX.rest.callMethod( 'catalog.documentcontractor.add', { fields: { documentId: 11, entityTypeId: 3, entityId: 21, }, }, function(result) { if (result.error()) console.error(result.answer.error_description); else console.log(result.data()); });
Identifier for documentId is known. Let's overview, where to source entityTypeId and entityId:
- entityTypeId – CRM entity ID. List for these entity types is registered (for Contact its
3
, for Company -4
). - entityId – CRM entity ID (vendor Contacts or vendor Companies). To get the list of required IDs for necessary CRM entities, you need to execute two actions:
- Use the method crm.category.list to get list of entities to pass entityTypeId (3 or 4) and filter by
category code
Filtering by category in the method crm.category.list is available from version crm 23.0.0.
(for Contact
CATALOG_CONTRACTOR_CONTACT
, for CompanyCATALOG_CONTRACTOR_COMPANY
):BX.rest.callMethod( 'crm.category.list', { entityTypeId: 3, filter: { code: 'CATALOG_CONTRACTOR_CONTACT', } }, r => console.log(r.data()) );
The response returns category data. The second step requires categoryId – category ID (it can match with entityTypeId).
- Next, get the list of CRM entities by the method crm.item.list, where you need to pass entity ID entityTypeId and filter by previously retrieved categoryId:
BX.rest.callMethod( 'crm.item.list', { entityTypeId: 3, // CRM entity type ID for Contact select: ['ID', 'NAME', 'LAST_NAME', 'CATEGORY_ID'], // fields for display, optional parameter filter: { categoryId: 3, // CRM entity category ID for vendor Contact, retrieved from crm.category.list }, }, r => console.log(r.data()) );
Returns list of vendor Contacts to be used in associations/bindings (Contact IDs are needed for entityId).
Similar to get list of vendor Companies:
BX.rest.callMethod( 'crm.item.list', { entityTypeId: 4, // CRM entity type ID for Company select: ['ID', 'TITLE', 'CATEGORY_ID'], // fields for display, optional filter: { categoryId: 4, // CRM entity category ID for vendor Company, retrieved from crm.category.list }, }, r => console.log(r.data()) );
- Use the method crm.category.list to get list of entities to pass entityTypeId (3 or 4) and filter by
category code
Filtering by category in the method crm.category.list is available from version crm 23.0.0.
(for Contact
© «Bitrix24», 2001-2024