将文件从 Google 上传到 Google 驱动器 表单文件上传重命名为从表单响应中收集的字段名称(字符串值)?

Upload files to Google Drive from Google forms file uploads renamed with field name (string value) collected from the Form Response?

此代码目前从表单响应中获取唯一 ID,并将其作为所有上传文件所在的文件夹名称。我想更改代码,以便它从组织视图的 Google 表单响应中获取一个文本字段,例如 First Name_Last Name.

const PARENT_FOLDER_ID = "2ih2384723847234878h23jkbi2j3b4ijb23i4bhwed34f";

const initialize = () => {
  const form = FormApp.getActiveForm();
  ScriptApp.newTrigger("onFormSubmit").forForm(form).onFormSubmit().create();
};

const onFormSubmit = ({ response } = {}) => {
  try {
    // Get a list of all files uploaded with the response
    const files = response
      .getItemResponses()
      // We are only interested in File Upload type of questions
      .filter(
        (itemResponse) =>
          itemResponse.getItem().getType().toString() === "FILE_UPLOAD"
      )
      .map((itemResponse) => itemResponse.getResponse())
      // The response includes the file ids in an array that we can flatten
      .reduce((a, b) => [...a, ...b], []);

    if (files.length > 0) {
      // Each form response has a unique Id
      const subfolderName = response.getId();
      const parentFolder = DriveApp.getFolderById(PARENT_FOLDER_ID);
      const subfolder = parentFolder.createFolder(subfolderName);
      files.forEach((fileId) => {
        // Move each file into the custom folder
        DriveApp.getFileById(fileId).moveTo(subfolder);
      });
    }
  } catch (f) {
    Logger.log(f);
  }
};

假设名字是第一题和第二题。

/* ... */

const n = response.getItemResponses().slice(0, 2)
const fn = n[0].getResponse();
const ln = n[1].getResponse();

/* ... */

const subfolderName = `${fn}_${ln}`;

/* ... */