Skip to content

informat.table Data Table Operations

Overview

Use the informat.table object for data table-related operations

Tip

Update, insert, and delete operations on data tables in scripts will not trigger listeners

Query Usage Examples

javascript
const query = {
  // Page number, starting from 1. Default is 1
  pageIndex: 1,
  // Number of records per page. Default is 100, -1 means query all data
  pageSize: 10,
  // Filter TableRecordFilter
  filter: {
    // Filter conditions TableRecordCondition
    conditionList: [
      {
        // Query field identifier
        fieldId: "name",
        /**
         * Comparison method TableRecordConditionOpt, values are as follows
         * eq                Equal
         * ne                Not equal
         * gt                Greater than
         * ge                Greater than or equal to
         * lt                Less than
         * le                Less than or equal to
         * contains          Contains
         * notcontains       Does not contain
         * startswith        Starts with
         * endswith          Ends with
         * isnull            Is null
         * isnotnull         Is not null
         * in                In list
         * notin             Not in list
         * between           Between
         * notbetween        Not between
         * parenteq          Parent object equals
         * parentrooteq      Root node equals
         * parentcontains    Parent object contains
         * multipleandquery  Multiple value AND fuzzy query
         * multipleorquery   Multiple value OR fuzzy query
         * intree            In tree
         */
        opt: "eq",
        /**
         * Processing function for data values TableRecordConditionFunc
         * Date type field values:
         * week                 Day of the week
         * month                Month of the year
         * quarter              Quarter of the year
         * year                 Year
         * dayofyear            Day of the year
         * weekofyear           Week of the year
         * dayofmonth           Day of the month
         * daytonow             Days from today
         * weektonow            Weeks from today
         * monthtonow           Months from today
         * quartertonow         Quarters from today
         * yeartonow            Years from today
         * fmtday               Year-month-day format:2021-01-01
         * fmtweek              Year-week format:2021-1
         * fmtmonth             Year-month format:2021-01
         * fmtquarter           Year-quarter format:2021-1
         * Member type field values:
         * nameOfAccount        Account name
         */
        func: null,
        // Comparison value
        value: "mr.zhang",
      },
      getTableInfo,
    ],
    // Nested sub-filters, value is an array of TableRecordFilter, supports nested structure layer by layer
    children: [],
    /**
     * Combination method of sub-filters and upper-level filters
     * Values are as follows
     * and      Match all
     * or       Match any
     */
    opt: "and",
  },
  // List of field identifiers included in the return value, query all fields if not passed or empty array
  includeFields: ["id", "name", "age"],
  // List of grouping field identifiers
  groupByList: [],
  // Aggregation query list TableRecordAggregationQuery
  aggregationQueryList: [
    {
      // Aggregated field
      fieldId: "sex",
      /**
       * Aggregation method
       * Values are as follows
       * count        Count
       * avg          Average (number, date type)
       * sum          Sum (number, date type)
       * max          Maximum value (number, date type)
       * min          Minimum value (number, date type)
       */
      func: "count",
      // Whether to deduplicate
      distinct: false,
    },
  ],
  // Sorting method array, OrderBy
  orderByList: [
    {
      // Sort field identifier
      field: "name",
      /**
       * Sorting method values:
       * asc      Ascending order
       * desc     Descending order
       */
      type: "desc",
    },
  ],
  // List of deduplicated field identifiers
  distinctFieldList: [],
  // Return value exclude field identifier list, query all fields if not passed or empty array
  excludeFields: [],
  // Whether to return option names, returns option names for `List Selection`, `Cascading Selection`, `Tree Selection`
  returnOptionName: false,
};

Notes

Difference between contains and in in TableRecordConditionOpt

For example: The task table has a responsible person field (identifier: owner, type: user selection, multiple selection), with the following records

IDResponsible Person
1Zhang San, Li Si
2Zhang San
3Wang Wu
  • Contains: The right member list contains any member from the left

    • { fieldId: 'owner', opt: 'contains', value: ['Zhang San'] } Records 1, 2 satisfy the condition
  • In list: The right member list contains all members from the left

    • { fieldId: 'owner', opt: 'in', value: ['Zhang San'] } Only record 2 satisfies the condition
    • { fieldId: 'owner', opt: 'in', value: ['Zhang San','Li Si'] } Records 1, 2 satisfy the condition

queryList

Query multiple data records by conditions

javascript
informat.table.queryList(tableId, query);
ParameterTypeDescription
tableIdStringData table identifier
queryTableRecordQueryQuery conditions

Return Value

List of data records, type: Array<Object>

queryListCount

Query the count of data that meets the conditions

javascript
informat.table.queryListCount(tableId, filter);
ParameterTypeDescription
tableIdStringData table identifier
filterTableRecordFilterQuery conditions

Return Value

The number of records that meet the conditions, type: Integer

Example

js
informat.table.queryListCount("staffs", {
  conditionList: [{ fieldId: "name", opt: "contains", value: "zhang" }],
});
json
2

getTableInfo

Query data table information

javascript
informat.table.getTableInfo(tableId);
ParameterTypeDescription
tableIdStringData table identifier

Return Value

Type: TableInfo, returns data table information

Example

js
informat.table.getTableInfo("task");
json
{
  "table": {
    "id": "cfg9ywr41G",
    "key": "task",
    "name": "task"
  },
  "tableFieldList": [
    {
      "id": "id",
      "key": "id",
      "name": "id",
      "type": "UUID"
    },
    {
      "id": "mzqlwrDgOM",
      "key": "expectDate",
      "name": "expectDate",
      "type": "Date"
    },
    {
      "id": "tp0rfnbmcc3sd",
      "key": "updateTime",
      "name": "updateTime",
      "type": "LastModifyTime"
    },
    {
      "id": "u3qh6zf0lgwus",
      "key": "updateUser",
      "name": "updateUser",
      "type": "LastModifyUser"
    },
    {
      "id": "Wfgb3bwKdf",
      "key": "name",
      "name": "name",
      "type": "SingleText"
    }
  ]
}

getTableFieldInfo

Query data table field information

javascript
informat.table.getTableFieldInfo(tableId, fieldId);
ParameterTypeDescription
tableIdStringData table identifier
fieldIdStringData table field identifier

Return Value

Type: TableFieldInfo, returns data table field information

Example

js
informat.table.getTableFieldInfo("task", "name");
json
{
  "changeLogAccessRoleList": [],
  "defaultValueRuleList": [],
  "displayWidth": 50,
  "enableChangeLog": true,
  "hidden": false,
  "icon": "text",
  "id": "Wfgb3bwKdf",
  "key": "name",
  "name": "name",
  "readonly": false,
  "singleTextSetting": {
    "autoCompleteAutomaticVarList": [],
    "autoCompleteTriggerOnFocus": false,
    "buttonList": [],
    "enableAutoComplete": false,
    "format": "string",
    "max": 200,
    "min": 0,
    "nullable": true,
    "storageSize": 200
  },
  "tableId": "task",
  "type": "SingleText",
  "validateRuleList": []
}

queryById

Query a single data record by ID

javascript
informat.table.queryById(tableId, recordId);
ParameterTypeDescription
tableIdStringData table identifier
recordIdStringID of the data record to query

Return Value

The queried data record, type: Object

Example

js
informat.table.queryById("task", "aorxux52i4t1z");
json
{
  "id": "aorxux52i4t1z",
  "name": "task1",
  "startDate": "2022-12-05 00:00:00.0"
}

queryOne

Query the first record that meets the conditions

javascript
informat.table.queryOne(tableId, query);
ParameterTypeDescription
tableIdStringData table identifier
queryTableRecordQueryQuery conditions

Return Value

The queried data record, type: Object

Example

js
informat.table.queryOne("task", {
  pageSize: 1,
  filter: {
    conditionList: [{ fieldId: "name", opt: "eq", value: "task1" }],
  },
});
json
{
  "id": "aorxux52i4t1z",
  "name": "task1",
  "startDate": "2022-12-05 00:00:00.0"
}

query

Query a single record by ID and conditions

javascript
informat.table.query(tableId, recordId, setting);
ParameterTypeDescription
tableIdStringData table identifier
recordIdStringID of the record to query
settingTableRecordQuerySettingQuery settings

The structure of TableRecordQuerySetting is as follows

ParameterTypeDescription
forUpdateBooleanWhether to lock the row
returnOptionNameBooleanIf there are List Selection, Cascading Selection, or Tree Selection fields, returns option names
includeFieldsArray<String>List of fields to return, returns all fields if empty

Return Value

The queried data record, type: Object

Example: Querying a record with row lock

js
informat.table.query("task", "aorxux52i4t1z", {
  forUpdate: true,
});
json
{
  "id": "aorxux52i4t1z",
  "name": "task1",
  "startDate": "2022-12-05 00:00:00.0"
}

insert

Create a record

For the four fields Creator, Creation Time, Last Modifier, and Last Modification Time, if they are not provided in the record to be created, the system will set the current time as the values for Creation Time and Last Modification Time, and set the current operator as the values for Creator and Last Modifier. If the record creation is triggered by a scheduled task, the current operator is INFORMAT.

javascript
informat.table.insert(tableId, data);
ParameterTypeDescription
tableIdStringData table identifier
dataObjectRecord to be created

Return Value

Returns the ID of the created record

Example

js
informat.table.insert("staffs", {
  name: "mr. zhao",
  sex: "male",
  age: 30,
  grade: 5,
  area: ["guangdong", "shenzhen", "nanshan"],
});
json
"twmvau4ogujcc"

For detailed formatting, see: Record Type Conversion

insertEx

Create a record with configuration information Similar to Create a record, the only difference is that it has configuration information

javascript
informat.table.insertEx(tableId, data, config);
ParameterTypeDescription
tableIdStringData table identifier
dataObjectRecord to be created
configInsertRecordConfigConfiguration info

The structure of InsertRecordConfig is as follows:

ParameterTypeDescription
disableCalculateRollupFieldBooleanWhether to disable rollup field calculation, default false

When creating a new record, if the table it belongs to is a child table of a main table, and some fields are rollup fields in the main table's lookup rollup or relation list rollup, the system will automatically calculate these rollup fields in the main table. For example, when creating a large number of child table records at once, it is actually unnecessary to recalculate the rollup fields in the main table every time a child table record is created, as the time required for calculating rollups is relatively long. Therefore, it is sufficient to recalculate the rollups only after the last child table record is created.

To improve efficiency and reduce unnecessary calculations, you can set the configuration parameter disableCalculateRollupField in InsertRecordConfig to true in such cases. This way, the system will not calculate rollup fields every time a child table record is created. After all child table records are created, you can then separately call informat.table.refreshRelationRollup and informat.table.refreshLookupRollup to calculate the rollups.

Return Value

ID of the created record

js
informat.table.insertEx(
  "staffs",
  {
    name: "mr. zhao",
    sex: "male",
    age: 30,
    grade: 5,
    area: ["guangdong", "shenzhen", "fukui"],
  },
  {
    disableCalculateRollupField: true,
  }
);
json
"ecxnsomw69dmn"

batchInsert

Batch create records

For the four fields Creator, Creation Time, Last Modifier, and Last Modification Time, if they are not provided in the records to be created, the system will set the current time as the values for Creation Time and Last Modification Time, and set the current operator as the values for Creator and Last Modifier. If the record creation is triggered by a scheduled task, the current operator is INFORMAT.

javascript
informat.table.batchInsert(tableId, dataList);
ParameterTypeDescription
tableIdStringData table identifier
dataListArrayList of records to be created

Return Value

Number of records created

Notes

Differences between batch inserting records and normal single record insertion:

The fields Child Object Number, Number, Lookup Rollup, and Relation List Rollup are not calculated during batch insertion of records.

update

Update a record For the two fields Last Modifier and Last Modification Time, if they are not provided in the record to be updated, the system will set the current time as the value for Last Modification Time, and set the current operator as the value for Last Modifier. If the record update is triggered by a scheduled task, the current operator is INFORMAT.

javascript
informat.table.update(tableId, data);
ParameterTypeDescription
tableIdStringData table identifier
dataObjectRecord to be updated

Return Value

Number of successfully updated records

Example 1

js
informat.table.update("staffs", {
  id: "1",
  name: "mr. zhao",
  sex: "male",
  age: 28,
  grade: 2,
  area: ["guangdong", "shenzhen", "fukui"],
});
json
1

For detailed formatting, see: Field Type Conversion

updateEx

Update a record with configuration information Similar to Update a record, the only difference is that it has update configuration information

javascript
informat.table.updateEx(tableId, data, config);
ParameterTypeDescription
tableIdStringData table identifier
dataObjectRecord to be updated
configUpdateRecordConfigUpdate configuration

The structure of UpdateRecordConfig is as follows:

ParameterTypeDescription
enableChangeLogBooleanWhether to enable change log, default false
disableCalculateRollupFieldBooleanWhether to disable rollup field calculation, default false

When updating a record, if the table it belongs to is a child table of a main table, and the updated field is a rollup field in the main table's lookup rollup or relation list rollup, the system will automatically calculate these rollup fields in the main table. For example, when updating a large number of child table records at once, it is actually unnecessary to recalculate the rollup fields in the main table every time a child table record is updated, as the time required for calculating rollups is relatively long. Therefore, it is sufficient to recalculate the rollups only after the last child table record is updated.

To improve efficiency and reduce unnecessary calculations, you can set the configuration parameter disableCalculateRollupField in UpdateRecordConfig to true in such cases. This way, the system will not calculate rollup fields every time a child table record is updated. After all child table records are updated, you can then separately call informat.table.refreshRelationRollup and informat.table.refreshLookupRollup to calculate the rollups.

Example 1

js
informat.table.updateEx(
  "staffs",
  {
    id: "1",
    name: "mr. zhao",
    sex: "male",
    age: 28,
    grade: 2,
    area: ["guangdong", "shenzhen", "fukui"],
  },
  {
    enableChangeLog: true,
    disableCalculateRollupField: true,
  }
);
json
1

Return Value

Number of successfully updated records

batchUpdate

Batch update records For the two fields Last Modifier and Last Modification Time, if they are not provided in the records to be updated, the system will set the current time as the value for Last Modification Time, and set the current operator as the value for Last Modifier. If the record update is triggered by a scheduled task, the current operator is INFORMAT. Note: The list of fields to be updated must be consistent across all records in the update list. If the value is null, it will be updated to null in batch.

javascript
informat.table.batchUpdate(tableId, dataList);
ParameterTypeDescription
tableIdStringData table identifier
dataListObjectList of records to update

Example

js
informat.table.batchUpdate("staffs", [
  { id: "1", name: "mr.zhao", sex: "male", age: 29, grade: 3, area: ["guangdong", "shenzhen", "nanshan"] },
  { id: "2", name: "mr.sun", sex: "female", age: 26, grade: 2, area: ["guangdong", "shenzhen", "baoan"] },
]);
json
3

Notes

Differences between batch updating records and normal single record updating:

The fields Child Object Number, Number, Lookup Rollup, and Relation List Rollup are not calculated during batch update of records.

updateList

Update multiple records according to conditions

javascript
informat.table.updateList(tableId, filter, data);
ParameterTypeDescription
tableIdStringData table identifier
filterFilterFilter conditions
dataObjectData to be updated

Return Value

Number of successfully updated records

Example: Update all employees with the last name "zhang" to level 4

js
informat.table.updateList(
  "staffs",
  {
    conditionList: [{ fieldId: "name", opt: "contains", value: "zhang%" }],
  },
  { grade: 4 }
);
json
2

updateListEx

Update multiple records according to conditions and configuration

javascript
informat.table.updateListEx(tableId, filter, data, config);
ParameterTypeDescription
tableIdStringData table identifier
filterFilterFilter conditions
dataObjectData to be updated
configUpdateRecordConfigUpdate configuration

The structure of UpdateRecordConfig is as follows:

ParameterTypeDescription
enableChangeLogBooleanWhether to enable change log, default false
disableCalculateRollupFieldBooleanWhether to disable rollup field calculation, default false

Return Value

Number of successfully updated records

Example:

js
informat.table.updateListEx(
  "staffs",
  {
    conditionList: [{ fieldId: "name", opt: "contains", value: "zhang%" }],
  },
  { grade: 4 },
  { disableCalculateRollupField: true }
);
json
2

delete

If the recycle bin is enabled, deleted records will be moved to the recycle bin. Delete a single record

javascript
informat.table.delete(tableId, recordId);
ParameterTypeDescription
tableIdStringData table identifier
recordIdStringID of the record to delete

Return Value

Number of successfully deleted records

Example:

js
informat.table.delete("staffs", "twmvau4ogujcc");
json
1

deleteEx

Delete a record with configuration information Similar to delete a record, the only difference is that it has configuration information

javascript
informat.table.deleteEx(tableId, recordId, config);
ParameterTypeDescription
tableIdStringData table identifier
recordIdStringID of the record to delete
configDeleteRecordConfigConfiguration information

The structure of DeleteRecordConfig is as follows:

ParameterTypeDescription
disableCalculateRollupFieldBooleanWhether to disable rollup field calculation, default false

When deleting a record, if the table it belongs to is a child table of a main table, and some fields are rollup fields in the main table's lookup rollup or relation list rollup, the system will automatically calculate these rollup fields in the main table. For example, when deleting a large number of child table records at once, it is actually unnecessary to recalculate the rollup fields in the main table every time a child table record is deleted, as the time required for calculating rollups is relatively long. Therefore, it is sufficient to recalculate the rollups only after the last child table record is deleted. To improve efficiency and reduce unnecessary calculations, you can set the configuration parameter disableCalculateRollupField in DeleteRecordConfig to true in such cases. This way, the system will not calculate rollup fields every time a child table record is deleted. After all child table records are deleted, you can then separately call informat.table.refreshRelationRollup and informat.table.refreshLookupRollup to calculate the rollups.

Return Value

Number of successfully deleted records

deleteList

If the recycle bin is enabled, deleted records will be moved to the recycle bin. Delete multiple records according to conditions

javascript
informat.table.deleteList(tableId, filter);
ParameterTypeDescription
tableIdStringData table identifier
filterFilterFilter conditions

Return Value

Number of successfully deleted records

Example: Delete the list of resigned employees

js
informat.table.deleteList("staffs", {
  conditionList: [{ fieldId: "status", opt: "ge", value: "dimission" }],
});
json
2

TIP

The underlying implementation logic of informat.table.deleteList is to first query all records and then delete them one by one. If the recycle bin is configured, the records will be moved to the recycle bin after deletion, so the speed is not fast. When batch deleting large amounts of data and faster speed is required, please use informat.table.batchDelete

deleteListEx

If the recycle bin is enabled, deleted records will be moved to the recycle bin. Delete multiple records according to conditions and configuration

javascript
informat.table.deleteListEx(tableId, filter, config);
ParameterTypeDescription
tableIdStringData table identifier
filterFilterFilter conditions
configDeleteRecordConfigConfiguration info

Return Value

Number of successfully deleted records

Example:

js
informat.table.deleteListEx(
  "user",
  {
    conditionList: [{ fieldId: "id", opt: "in", value: ["k3oybvxo0lwxv", "htfesu6ghbcro"] }],
  },
  {
    disableCalculateRollupField: true,
  }
);
json
2

batchDelete

Batch delete records If the recycle bin is enabled, deleted records will not be moved to the recycle bin.

javascript
informat.table.batchDelete(tableId, idList);
ParameterTypeDescription
tableIdStringData table identifier
idListArrayList of record IDs

Example

js
informat.table.batchDelete("staffs", ["uphuksrz88xij", "cyljta5v60mup"]);
json
2

queryRelationList

Query the record list of the child table corresponding to the relation list field through the main table record ID

javascript
informat.table.queryRelationList(tableId, relationFieldId, recordId, query);
ParameterTypeDescription
tableIdStringData table identifier
relationFieldIdStringRelation list field ID
recordIdStringMain table record ID
queryQueryChild table query criteria

Return Value

List of data records, type is Array<Object>

Example

javascript
informat.table.queryRelationList("staffs", "rewardList", "yhg8b23ej2gt6", {
  pageIndex: 1,
  pageSize: 50,
  filter: {
    conditionList: [{ fieldId: "name", opt: "contains", value: "excellent employee" }],
  },
});

addRelation

Add relation list value

javascript
informat.table.addRelation(tableId, relationFieldId, recordId, relationRecordId);
ParameterTypeDescription
tableIdStringData table identifier
relationFieldIdStringRelation list field
recordIdStringMain table record ID
relationRecordIdStringRelation list record ID

Example

javascript
informat.table.addRelation("staffs", "rewardList", "yhg8b23ej2gt6", "rgf4fbbb543kj");

deleteRelation

Delete relation list value

javascript
informat.table.deleteRelation(tableId, relationFieldId, recordId, relationRecordId);
ParameterTypeDescription
tableIdStringData table identifier
relationFieldIdStringRelation list field
recordIdStringMain table record ID
relationRecordIdStringRelation list record ID

Example

javascript
informat.table.deleteRelation("staffs", "rewardList", "yhg8b23ej2gt6", "rgf4fbbb543kj");

hasRelation

Query whether records are in the relation list If the record ID specified in relationRecordIdList exists in the relation list, this record ID is also included in the returned array.

For example, if the data stored in the relation list is:

  • record1
  • record2
  • record3

And relationRecordIdList is record1 record2 record4, then the return value is record1 record2

javascript
informat.table.hasRelation(tableId, relationFieldId, recordId, relationRecordIdList);
ParameterTypeDescription
tableIdStringData table identifier
relationFieldIdStringRelation list field
recordIdStringMain table record ID
relationRecordIdListArray<String>List of relation record IDs

Return Value

List of record IDs that exist in the relationFieldId relation list of recordId, type is Array<String>

Example

javascript
informat.table.hasRelation("staffs", "rewardList", "yhg8b23ej2gt6", ["rgf4fbbb543kj", "ct82dszf20s2u"]);
// Return data as follows:
["rgf4fbbb543kj"];

getRelationRecordIdList

Query the record list that contains the specified record in the relation list Query data related to the main table through the record ID in the target table associated with the relation list field. Returns a list of main table record IDs that have associations.

For example, if the data stored in the data table is as follows:

Main table record IDRelation list
m1[record1,record2]
m2[record1,record3]
m3[record3,record4]

If the specified record is record3, the return value is m2 m3

javascript
informat.table.getRelationRecordIdList(tableId, relationFieldId, recordId);
ParameterTypeDescription
tableIdStringMain table data table identifier
relationFieldIdStringRelation list field ID of main table
recordIdStringRecord ID of child table

Return Value

List of record IDs where recordId exists in the relationFieldId relation list, type is Array<String>

Example

javascript
informat.table.getRelationRecordIdList("staffs", "rewardList", "rgf4fbbb543kj");
// Return data as follows:
["yhg8b23ej2gt6"];

updateChildrenField

Update children field

Move the record under parentRecordId. If the current record has child nodes, the child nodes will be updated synchronously

javascript
informat.table.updateChildrenField(tableId, childrenFieldId, recordId, parentRecordId);
ParameterTypeDescription
tableIdStringData table identifier
childrenFieldIdStringChildren field
recordIdStringRecord ID to be updated
parentRecordIdStringParent node to move to. If parent node is null, the record will be moved to the root directory

Example

javascript
informat.table.updateChildrenField("task", "children", "z00ei9fqymbra", "zzzq65nxu0qv1");

queryChildrenList

Query the children record list of the specified record through conditions

javascript
informat.table.queryChildrenList(tableId, childrenFieldId, recordId, query);
ParameterTypeDescription
tableIdStringData table identifier
childrenFieldIdStringChildren field
recordIdStringMain table record ID
queryQueryQuery conditions

Example

js
informat.table.queryChildrenList("staffsDept", "children", "rpev2ztqnbu8o", {
  pageIndex: 1,
  pageSize: 50,
});
json
[
  {
    "children": "rpev2ztqnbu8o",
    "createTime": 1717500998762,
    "name": "Technical Group 1",
    "id": "pz9y1fse8hccw",
    "seq": 5
  },
  {
    "children": "rpev2ztqnbu8o",
    "createTime": 1717501030793,
    "name": "Technical Group 2",
    "id": "l8w9u9raftp2a",
    "seq": 6
  }
]

cloneAttachment

Copy files from attachment field to target field Copy files from the attachment field in the source data table to the attachment field in the target table.

TIP

Note: attachment is an object, not an array. If the attachment field is multi-select, you need to use array index to select the corresponding attachment object

javascript
informat.table.cloneAttachment(sourceTableId, sourceFieldId, targetTableId, targetFieldId, attachment);
ParameterTypeDescription
sourceTableIdStringSource data table identifier
sourceFieldIdStringSource field identifier
targetTableIdStringTarget data table identifier
targetFieldIdStringTarget field identifier
attachmentTableAttachmentAttachment object

Return Value

Attachment object after successful copy, type is TableAttachment

Example

js
var record = informat.table.queryById("staffs", "yhg8b23ej2gt6");
console.log("record.attachment", record.attachment);
if (record.attachment == null) {
  return null;
}
var targetAttachments = [];
record.attachment.forEach((att) => {
  //checkbox
  var targetAttachment = informat.table.cloneAttachment("staffs", "attachment", "staffsDept", "attachment", att);
  targetAttachments.push(targetAttachment);
});
console.log("targetAttachments", targetAttachments);
informat.table.update("staffsDept", {
  id: "pz9y1fse8hccw",
  attachment: targetAttachments,
});
json
[
  {
    "id": "1d14a4c1080e4f5992052aeab13951df.jpg",
    "md5": "b394f37c3180e68090e2a0f1370f2aa9",
    "name": "test.jpg",
    "path": "uljrmxosme2uw/dwbndumn3dc8k/1d14a4c1080e4f5992052aeab13951df.jpg",
    "size": 7757,
    "thumbnail": "c270728528b54876abf67fb7e9ec4f24.jpg"
  }
]

moveAttachment

Move files from attachment field to target attachment field Move files from the attachment field in the source data table to the attachment field in the target table.

TIP

Note: attachment is an object, not an array. If the attachment field is multi-select, you need to use array index to select the corresponding attachment object

javascript
informat.table.moveAttachment(sourceTableId, sourceFieldId, targetTableId, targetFieldId, attachment);
ParameterTypeDescription
sourceTableIdStringSource data table identifier
sourceFieldIdStringSource field identifier
targetTableIdStringTarget data table identifier
targetFieldIdStringTarget field identifier
attachmentTableAttachmentAttachment object

Return Value

Attachment object after successful move, type is TableAttachment

Example

javascript
var record = informat.table.queryById("task", "cyrzgschwivz1");
informat.table.moveAttachment("task", "attachment", "task2", "attachment", record.attachment);

createAttachment

Generate attachment using files from local sandbox Upload files from local sandbox to shared storage and generate TableAttachment objects. If the file is an image type, the system will automatically generate a thumbnail; if there is a watermark setting in the attachment settings, the system will automatically generate a watermark.

javascript
informat.table.createAttachment(tableId, fieldId, path);
ParameterTypeDescription
tableIdStringIdentifier of the data table
fieldIdStringIdentifier of the attachment field
pathStringFile path in the local sandbox

Return Value

The attachment field after successful creation, type is TableAttachment

Example

Download images from URL, save to local sandbox files, then use files from local sandbox to generate attachments and save to the attachment field of a record in the staff table

The staff table staffs has an attachment field

Field IDTypeDescription
attachmentAttachmentMultiple selection
javascript
const req = {
  url: "https://www.informat.cn/favicon.ico",
};
const rsp = informat.http.request(req);
// Save to local sandbox
rsp.saveBodyAsFile("tmp/demo.png");
var attachment = informat.table.createAttachment("staffs", "attachment", "tmp/demo.png");
// Update the attachment field of the data table record
informat.table.update("staffs", {
  id: "yhg8b23ej2gt6",
  attachment: [attachment], // Because the attachment field is multiple selection, use an array here; similarly, if it is not multiple selection, no need to use an array
});
// Delete local file
informat.file.delete("tmp/demo.png");

createAttachmentStorage

Generate attachment using files from remote storage Copy files from remote storage as values for attachment fields. If the file is an image type, no thumbnail will be generated, and the thumbnail value will be the same as the attachment value. This operation also does not generate watermarks.

javascript
informat.table.createAttachmentStorage(tableId, fieldId, path);
ParameterTypeDescription
tableIdStringIdentifier of the data table
fieldIdStringIdentifier of the attachment field
pathStringFile path in remote storage

Return Value

The attachment field after successful creation, type is TableAttachment

Example

Download images from URL, save to shared storage, then use files from remote storage to generate attachments and save to the attachment field of a record in the staff table

The staff table staffs has an attachment field

Field IDTypeDescription
attachmentAttachmentMultiple selection
javascript
const req = {
  url: "https://www.informat.cn/favicon.ico",
};
const rsp = informat.http.request(req);
// Save to remote storage
rsp.saveBodyAsStorage("remote/demo.png");
var attachment = informat.table.createAttachmentStorage("staffs", "attachment", "remote/demo.png");
// Update the attachment field of the data table record
informat.table.update("staffs", {
  id: "lc44f3lfggnbb",
  attachment: [attachment], // Because the attachment field is multiple selection, use an array here; similarly, if it is not multiple selection, no need to use an array
});
// Delete local file
informat.file.delete("tmp/demo.png");

cloneTableSignature

Copy files from handwritten signature field to target field Copy files from the handwritten signature field in the source data table to the handwritten signature field in the target table.

javascript
informat.table.cloneTableSignature(sourceTableId, sourceFieldId, targetTableId, targetFieldId, signature);
ParameterTypeDescription
sourceTableIdStringIdentifier of the source data table
sourceFieldIdStringIdentifier of the source field
targetTableIdStringIdentifier of the target data table
targetFieldIdStringIdentifier of the target field
signatureTableSignatureHandwritten signature object

Return Value

Handwritten signature after successful copying, type is TableSignature

Example

Automatically upload handwritten signatures to a custom form, then copy the handwritten signature attachments from the custom form to the handwritten signature field of a record in the staff table staffs.

Custom form data table identifier: $Automatic_b0qt6ci821n2m_nuxfjrga56kj Custom form data table has a handwritten signature field (single selection) Staff table staffs has a handwritten signature field (single selection)

Field IDTypeDescription
signatureHandwrittenSingle selection
javascript
let form = automatic.getVar("form");
let signature = informat.table.cloneTableSignature("$Automatic_b0qt6ci821n2m_nuxfjrga56kj", "signature", "staffs", "signature", form.signature);
informat.table.update("staffs", {
  id: "yhg8b23ej2gt6",
  signature: signature,
});

refreshDataSource

Refresh materialized view data When the data source is from a database view and the materialized view option is enabled, it will refresh the materialized view data. It will throw an exception in other cases.

javascript
informat.table.refreshDataSource(tableId);
ParameterTypeDescription
tableIdStringIdentifier of the data table

Example

javascript
informat.table.refreshDataSource("techStaffsView");

refreshRelationRollup

Recalculate the value of relation list rollup field

javascript
informat.table.refreshRelationRollup(tableId, fieldId, recordIdList);
ParameterTypeDescription
tableIdStringData table identifier
fieldIdStringRelation list rollup field identifier
recordIdListStringList of main table record IDs. If empty, recalculate the entire table

Example

javascript
informat.table.refreshRelationRollup("staffs", "rewardCount", null); // Recalculate all records
informat.table.refreshRelationRollup("staffs", "rewardCount", ["yhg8b23ej2gt6"]); // Only recalculate the rollup data corresponding to yhg8b23ej2gt6

refreshLookupRollup

Recalculate the value of lookup list rollup field

javascript
informat.table.refreshLookupRollup(tableId, fieldId, recordIdList, subFilter);
ParameterTypeDescription
tableIdStringData table identifier
fieldIdStringLookup list rollup field identifier
recordIdListArray<String>List of main table record IDs. If empty, recalculate the entire table
subFilterFilterChild table filter condition, can be empty

Example

javascript
informat.table.refreshLookupRollup("staffs", "totalLevelDays", null, null); // Recalculate all records
informat.table.refreshLookupRollup("staffs", "totalLevelDays", ["yhg8b23ej2gt6"], null); // Only recalculate yhg8b23ej2gt6

queryChangeLogListCount

Get the total number of change records

javascript
informat.table.queryChangeLogListCount(tableId, filter);
ParameterTypeDescription
tableIdStringData table identifier
filterFilterFilter conditions

List of fields that can be used in the filter

FieldTypeDescription
idIntegerChange record ID
fieldNameStringField name
recordIdStringRecord ID
createUserIdStringCreator ID

Return Value Type is Integer Returns the total number of change records

Example

javascript
const count = informat.table.queryChangeLogListCount("tableKey", {
  conditionList: [
    {
      fieldId: "recordId",
      opt: "eq",
      value: "gn43hedzzgztp",
    },
  ],
});
// Get the matching count
console.log("count:", count);

queryChangeLogList

Query change record list

javascript
informat.table.queryChangeLogList(tableId, informatQuery);
ParameterTypeDescription
tableIdStringData table identifier
informatQueryQueryQuery conditions

List of fields that can be used in the filter

FieldTypeDescription
idIntegerChange record ID
fieldNameStringField name
recordIdStringRecord ID
createUserIdStringCreator ID

Return Value Type is Array<TableChangeLog> Returns change record list

Example

js
informat.table.queryChangeLogList("staffs", {
  pageIndex: 1,
  pageSize: 20,
  filter: {
    conditionList: [
      {
        fieldId: "recordId",
        opt: "eq",
        value: "yhg8b23ej2gt6",
      },
    ],
  },
});
json
[
  {
    "afterValue": {
      "type": "RelationRecord",
      "value": "fh1snm1k18kqc",
      "multiple": false,
      "valueString": "Sales Department"
    },
    "beforeValue": {
      "type": "RelationRecord",
      "multiple": false
    },
    "fieldName": "Department",
    "id": "1",
    "recordId": "yhg8b23ej2gt6"
  }
]

queryCommentListCount

Get total number of form comments

javascript
informat.table.queryCommentListCount(tableId, filter);
ParameterTypeDescription
tableIdStringData table identifier
filterFilterFilter conditions

List of fields that can be used in the filter

FieldTypeDescription
idintComment ID
commentStringComment content
isDeletedBooleanIs deleted
parentIdIntegerReply comment ID
recordIdStringRecord ID
createUserIdStringCreator ID

Return Value Type is Integer Returns total number of form comments

Example

js
informat.table.queryCommentListCount("staffs", {
  conditionList: [
    {
      fieldId: "recordId",
      opt: "eq",
      value: "yhg8b23ej2gt6",
    },
  ],
});
json
1

queryCommentList

Query form comment list

javascript
informat.table.queryCommentList(tableId, query);
ParameterTypeDescription
tableIdStringData table identifier
queryQueryQuery conditions

List of fields that can be used in the filter

FieldTypeDescription
idintComment ID
commentStringComment content
isDeletedBooleanIs deleted
parentIdIntegerReply comment ID
recordIdStringRecord ID
createUserIdStringCreator ID

Return Value Type is Array<TableComment> Returns form comment list

Example

js
informat.table.queryCommentList("staffs", {
  pageIndex: 1,
  pageSize: 20,
  filter: {
    conditionList: [
      {
        fieldId: "recordId",
        opt: "eq",
        value: "yhg8b23ej2gt6",
      },
    ],
  },
});
json
[
  {
    "comment": "{\"type\":\"doc\",\"content\":[{\"type\":\"paragraph\",\"content\":[{\"text\":\"Good\",\"type\":\"text\"}]}]}",
    "createTime": 1717728322411,
    "createUserAvatar": "79a487eb7f384321bfaed16eb9e020d8.jpg",
    "createUserId": "skydu",
    "createUserName": "mr.du",
    "delete": false,
    "id": 1,
    "isDelete": false,
    "parentId": 0,
    "recordId": "yhg8b23ej2gt6"
  }
]

addComment

Add form comment

javascript
informat.table.addComment(tableId, tableComment);
ParameterTypeDescription
tableIdStringData table identifier
tableCommentTableCommentFormForm comment

Return Value Type is Integer Returns newly added ID

Comment Example

js
informat.table.addComment("staffs", {
  recordId: "yhg8b23ej2gt6",
  content: "Comment content",
  createUserId: "skydu", // Optional
});
json
2

Reply Comment Example

js
informat.table.addComment("staffs", {
  recordId: "yhg8b23ej2gt6",
  parentId: 2, // Optional
  content: "Reply to previous comment",
  createUserId: "skydu", // Optional
});
json
3

deleteComment

Delete form comment

TIP

If the comment has replies, it will be logically deleted; otherwise, it will be physically deleted. If the comment does not exist, an error will be reported indicating the comment does not exist.

javascript
informat.table.deleteComment(tableId, commentId);
ParameterTypeDescription
tableIdStringData table identifier
commentIdIntegerForm comment Id

Example

javascript
informat.table.deleteComment("staffs", 3);

getIdFieldSeq

Get current auto-increment sequence of number field

javascript
informat.table.getIdFieldSeq(tableId, fieldId);
ParameterTypeDescription
tableIdStringData table identifier
fieldIdStringNumber field identifier

Return Value Type is Integer Returns current auto-increment sequence

Example

js
informat.table.getIdFieldSeq("task", "number");
js
2

setIdFieldSeq

Set auto-increment sequence of number field

javascript
informat.table.setIdFieldSeq(tableId, fieldId, seq);
ParameterTypeDescription
tableIdStringData table identifier
fieldIdStringNumber field identifier
seqIntegerAuto-increment sequence

Example

javascript
informat.table.setIdFieldSeq("staffs", "staffNo", 10);

updateRecordSeq

Update data table sort sequence

javascript
informat.table.updateRecordSeq(tableId, recordId, seq);
ParameterTypeDescription
tableIdStringData table identifier
recordIdStringData table record ID
seqIntegerNew sort sequence

Example

javascript
informat.table.updateRecordSeq("staffs", "yhg8b23ej2gt6", 101);

moveRecord

Move record

TIP

After moving, seq will be recalculated in order

javascript
informat.table.moveRecord(tableId, recordId, targetRecordId, type);
ParameterTypeDescription
tableIdStringData table identifier
recordIdStringRecord ID
targetRecordIdStringTarget record ID
typeStringDrag method. Optional values are as follows:
before: Move record before target record
after: Move record after target record

Example

javascript
informat.table.moveRecord("task", "ksrhoqarae7hj", "dvmdfh74m0s2w", "before");

moveTreeViewRecord

Move record in tree view

javascript
informat.table.moveTreeViewRecord(tableId, childrenFieldId, recordId, parentRecordId, targetRecordId, type);
ParameterTypeDescription
tableIdStringData table identifier
childrenFieldIdStringChildren field
recordIdStringRecord ID
parentRecordIdStringParent record ID. Not required when moving at the same level
targetRecordIdStringTarget record ID
typeStringDrag method. Optional values are as follows:
before: Move record before target record
after: Move record after target record
inner: Inside parent object

Example 1 Move record at the same level

javascript
informat.table.moveTreeViewRecord("staffsDept", "children", "l8w9u9raftp2a", null, "pz9y1fse8hccw", "before");

Example 2 Move record to a new parent record

javascript
informat.table.moveTreeViewRecord("staffsDept", "children", "l8w9u9raftp2a", "fh1snm1k18kqc", "u3lma96ibq52h", "before");

moveLookupFieldRecord

Move record in lookup field list

javascript
informat.table.moveLookupFieldRecord(tableId, lookupFieldId, mainRecordId, recordId, targetRecordId, type);
ParameterTypeDescription
tableIdStringData table identifier
lookupFieldIdStringLookup field
mainRecordIdStringMain table record ID
recordIdStringChild table record ID
targetRecordIdStringChild table target record ID
typeStringDrag method. Optional values are as follows:
before: Move record before target record
after: Move record after target record

Example

javascript
informat.table.moveLookupFieldRecord("staffs", "leaveLogRel", "yhg8b23ej2gt6", "p54xumqba4kmm", "vdbt9kk1cugvy", "before");

moveRelationFieldRecord

Move record in relation field list

javascript
informat.table.moveRelationFieldRecord(tableId, relationFieldId, mainRecordId, recordId, targetRecordId, type);
ParameterTypeDescription
tableIdStringData table identifier
relationFieldIdStringRelation field
mainRecordIdStringMain table record ID
recordIdStringChild table record ID
targetRecordIdStringChild table target record ID
typeStringDrag method. Optional values are as follows:
before: Move record before target record
after: Move record after target record

Example

javascript
informat.table.moveRelationFieldRecord("staffs", "rewardList", "yhg8b23ej2gt6", "vsf3lo6ryj6lc", "ct82dszf20s2u", "before");

moveChildrenFieldRecord

Move record in children field

javascript
informat.table.moveChildrenFieldRecord(tableId, childrenFieldId, mainRecordId, recordId, targetRecordId, type);
ParameterTypeDescription
tableIdStringData table identifier
childrenFieldIdStringChildren field
mainRecordIdStringMain table record ID
recordIdStringChild table record ID
targetRecordIdStringChild table target record ID
typeStringDrag method. Optional values are as follows:
before: Move record before target record
after: Move record after target record

Example

javascript
informat.table.moveChildrenFieldRecord("staffsDept", "children", "rpev2ztqnbu8o", "l8w9u9raftp2a", "pz9y1fse8hccw", "before");

moveLookupFieldTreeViewRecord

Move record in lookup field tree view

javascript
informat.table.moveLookupFieldTreeViewRecord(tableId, lookupFieldId, childrenFieldId, mainRecordId, recordId, parentRecordId, targetRecordId, type);
ParameterTypeDescription
tableIdStringData table identifier
lookupFieldIdStringLookup field
childrenFieldIdStringChildren field
mainRecordIdStringMain table record ID
recordIdStringChild table record ID
parentRecordIdStringParent record ID
targetRecordIdStringChild table target record ID
typeStringDrag method. Optional values are as follows:
before: Move record before target record
after: Move record after target record
inner: Inside parent object

Example

javascript
informat.table.moveLookupFieldTreeViewRecord("lookup", "lookup_children", "children", "ozyqa05tj4xs0", "xim3193k04lu0", null, "pjrpekzh9gc2j", "before");

moveRelationFieldTreeViewRecord

Move record in relation field tree view

javascript
informat.table.moveRelationFieldTreeViewRecord(tableId, relationFieldId, childrenFieldId, mainRecordId, recordId, parentRecordId, targetRecordId, type);
ParameterTypeDescription
tableIdStringData table identifier
relationFieldIdStringRelation field
childrenFieldIdStringChildren field
mainRecordIdStringMain table record ID
recordIdStringChild table record ID
parentRecordIdStringParent record ID
targetRecordIdStringChild table target record ID
typeStringDrag method. Optional values are as follows:
before: Move record before target record
after: Move record after target record
inner: Inside parent object

Example

javascript
informat.table.moveRelationFieldTreeViewRecord("relation", "relation_children", "children", "xzyqa35tj4xsq", "kim3193k54lu8", null, "fjrpekzh9gc6h", "before");

moveChildrenFieldTreeViewRecord

Move record in children field tree view

javascript
informat.table.moveChildrenFieldTreeViewRecord(tableId, mainChildrenFieldId, childrenFieldId, mainRecordId, recordId, parentRecordId, targetRecordId, type);
ParameterTypeDescription
tableIdStringData table identifier
mainChildrenFieldIdStringChildren field
childrenFieldIdStringChildren field
mainRecordIdStringMain table record ID
recordIdStringChild table record ID
parentRecordIdStringParent record ID
targetRecordIdStringChild table target record ID
typeStringDrag method. Optional values are as follows:
before: Move record before target record
after: Move record after target record
inner: Inside parent object

Example

javascript
informat.table.moveChildrenFieldTreeViewRecord("children", "children_children", "children", "izyqa25tj4xsp", "iim3103k54lup", null, "ilrpekzh3gc2p", "before");

refreshIndexNumber

Recalculate children field index numbers

javascript
informat.table.refreshIndexNumber(tableId, fieldId, parentRecordId);
ParameterTypeDescription
tableIdStringData table identifier
fieldIdStringChildren field index number field
parentRecordIdStringParent record ID, can be empty; when empty, recalculate all index numbers

Example

javascript
informat.table.refreshIndexNumber("staffsDept", "indexNumber", "rpev2ztqnbu8o"); // Recalculate child record list for parent record
informat.table.refreshIndexNumber("staffsDept", "indexNumber", null);