Documentation

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:

  1. 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.
  2. Get the ID list of uploaded files.
  3. 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

ParameterDescription
IBLOCK_TYPE_IDInformation block ID (required):
  • lists - information block type for lists
  • bitrix_processes - information block type for processes
  • lists_socnet - information block type for group lists
IBLOCK_CODE/IBLOCK_IDcode or ID for information block (required)
ELEMENT_CODE/ELEMENT_IDcode or ID for element (required)
LIST_ELEMENT_URLTemplate for list element URL
FIELDSarray of fields and values
SOCNET_GROUP_IDgroup 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
Up