createRecords()

The createRecords() function (server-side) creates or updates multiple records at the same time. To do this, the function calls createRecord() for each record you provide.

Syntax

Use this syntax for the createRecords() function:

            createRecords({
  records: [
    {
      type: 'recordType',
      id: recordId,
      fields: {
        fieldId1: 'value1',
        fieldId2: 'value2',
        // Additional fields
      },
      sublists: {
        sublistId1: [
          {
            sublistFieldId1: 'value1',
            sublistFieldId2: 'value2',
            // Additional sublist fields
          },
          // Additional sublist lines
        ],
        sublistId2: [
          {
            sublistFieldId1: 'value1',
            sublistFieldId2: 'value2',
            // Additional sublist fields
          },
          // Additional sublist lines
        ],
        // Additional sublists
      },
      // Additional records
    }
  ]
}).done(callback); 

          

Return Value

The createRecords() function returns a promise that resolves to an array of objects-one for each record created or updated. Each object in the array contains the ID of a created or updated item. The object returned contains the following information:

            [
  { "id": number1 },
  { "id": number2 },
  // ...,
  { "id": numbern }
] 

          

Parameters

Note:

Required properties:

  • records

  • type

When creating records, the fields property is also required. If you want to update records, include also the id.

The createRecords() function takes a single object as a parameter. The object includes the records property, which is an array of objects representing the records you want to create or update. Each record object includes the following properties:

  • type (string) - Specifies the item type ID to be created or updated, for example, inventoryitem or assebmlyitem.

  • fields (object) - Lists key-value pairs representing the field IDs to be set or updated.

  • sublists (object) - Lists key-value pairs where each key is a sublist name, and each value is an array of objects representing the sublist lines. Each sublist line object contains key-value pairs for the sublist field IDs and their values.

  • id (number) - Specifies the internal ID of the item to be updated.

Examples

The following examples show how to use the createRecords() function.

Creating Records

This example creates an inventory item.

              createRecords({
  records: [
    {
      type: 'inventoryitem',
      fields: {
        itemid: 'ITCR0005',
        displayname: 'Item c005',
        includechildren: 'T',
        cogsaccount: 213,
        assetaccount: 118,
        taxschedule: 1
      }
    }
  ]
}).done(function(data) {
  console.log(data);
}); 

            

Related Topics

General Notices