MCPcopy Create free account
hub / github.com/apitable/apitable / setRecords

Method setRecords

packages/widget-sdk/src/model/datasheet.ts:494–532  ·  view source on GitHub ↗

* Updates cell values for records. * @param records Specify the records be modified. * @return * * #### Description * Throws an error if the user does not have permission to update the given cell values in the record, or or recordId does not exist, * or when the written value type

(records: { id: string, valuesMap: { [key: string]: any } }[])

Source from the content-addressed store, hash-verified

492 * ```
493 */
494 async setRecords(records: { id: string, valuesMap: { [key: string]: any } }[]) {
495 const recordIds: string[] = [];
496 const recordsValues: { [key: string]: any }[] = [];
497 for (const record of records) {
498 recordIds.push(record.id);
499 recordsValues.push(record.valuesMap);
500 }
501 const state = this.wCtx.widgetStore.getState() as any as IReduxState;
502 const transformedRecordsValues = this.transformRecordValues(recordsValues);
503 this.checkRecordsValues(transformedRecordsValues);
504
505 const data = records.reduce<ISetRecordOptions[]>((pre, record) => {
506 const recordId = record.id;
507 const recordData = Selectors.getRecord(state, recordId, this.datasheetId);
508 if (!recordData) {
509 throw new Error(`RecordId: ${recordId} is not exist in datasheet`);
510 }
511
512 this.transformRecordValues([record.valuesMap]).forEach(valueMap => {
513 Object.entries(valueMap).forEach(([fieldId, cellValue])=> {
514 pre.push({
515 recordId,
516 fieldId,
517 value: cellValue,
518 });
519 });
520 });
521 return pre;
522 }, []);
523
524 const result: ICollaCommandExecuteResult<any> = await cmdExecute({
525 cmd: CollaCommandName.SetRecords,
526 datasheetId: this.datasheetId,
527 data,
528 }, this.wCtx.id);
529 if (result.result === ExecuteResult.Fail) {
530 throw new Error(result.reason);
531 }
532 }
533
534 /**
535 * Delete the given record.

Callers 5

setRecordMethod · 0.95
updateRecordsAsyncMethod · 0.45
datasheet.spec.tsFile · 0.45
dragWithinViewFunction · 0.45
setRecordFunction · 0.45

Calls 5

transformRecordValuesMethod · 0.95
checkRecordsValuesMethod · 0.95
cmdExecuteFunction · 0.90
pushMethod · 0.45
forEachMethod · 0.45

Tested by

no test coverage detected