async function processDocument()

in appscript/main.gs [130:160]


async function processDocument(documentType, contentBase64, isGetDocumentFields) {
  let keyRemapList = getCore().getDataList('Fields');
  keyRemapList.forEach(item => {
    item.key = item.docai.data.key;
    item.newKey = item.docai.data.newKey;
  });

  let settings = getCore().getDataJson('Settings');
  let response = await getCore().run({
    gatherer: ['docai'],
    srcData: {
      documentType: documentType,
      contentBase64: contentBase64,
    },
    destDatasetId: documentTypeMap[documentType].destDatasetId,
    docai: {
      authorization: 'Bearer ' + settings.oauthToken,
      projectId: settings.projectId,
      processorId: documentTypeMap[documentType].processorId,
      keyRemapList: keyRemapList,
    },
  });

  if (isGetDocumentFields) {
    await getDocumentFields();
  }

  if (response.errors && response.errors.length > 0) {
    SpreadsheetApp.getUi().alert(response.errors);
  }
}