lists.element.add
lists.element.add (params, fields)
This method creates a list element. Returns true on success, otherwise throws an exception.
To upload files in the File (drive) field type, proceed as follows:
- Use REST API of the disk module: disk.folder.uploadfile and disk.storage.uploadfile. The response will contain the "ID": 290 when the files are uploaded.
- Get the ID list of uploaded files.
- Then add files to the required field via the List module REST API:
var params = { 'IBLOCK_TYPE_ID': 'lists', 'IBLOCK_ID': '41', 'ELEMENT_CODE': 'element1', 'FIELDS': { 'NAME': 'Test element 1', 'PROPERTY_121': { 'n0':["n1582"]} } }; BX.rest.callMethod( 'lists.element.add', params, function(result) { if(result.error()) alert("Error: " + result.error()); else alert("Success: " + result.data()); } );
Parameters
Parameter | Description |
---|---|
IBLOCK_TYPE_ID | Information block ID (required):
|
IBLOCK_CODE/IBLOCK_ID | code or ID for information block (required) |
ELEMENT_CODE/ELEMENT_ID | code or ID for element (required) |
LIST_ELEMENT_URL | Template for list element URL |
FIELDS | array of fields and values |
SOCNET_GROUP_ID | group ID (required, if list is created for group); |
Examples
var params = { 'IBLOCK_TYPE_ID': 'lists_socnet', 'IBLOCK_CODE': 'rest_1', 'ELEMENT_CODE': 'element_1', 'LIST_ELEMENT_URL': '#list_id#/element/#section_id#/#element_id#/', 'FIELDS': { 'NAME': 'Test element', 'PROPERTY_62': 'Text string', 'PROPERTY_63': { '0': '7', '1': '9', '2': '10' } } }; BX24.callMethod( 'lists.element.add', params, function(result) { if(result.error()) alert("Error: " + result.error()); else alert("Success: " + result.data()); } );
Example of adding a file:
var params = { 'IBLOCK_TYPE_ID': 'lists', 'IBLOCK_ID': '41', 'ELEMENT_CODE': 'element1', 'FIELDS': { 'NAME': 'Test element 1', 'PROPERTY_122': document.getElementById('fileInputId') // PROPERTY_122 - File-type user property } }; BX.rest.callMethod( 'lists.element.add', params, function(result) { if(result.error()) alert("Error: " + result.error()); else alert("Success: " + result.data()); } );
© «Bitrix24», 2001-2024