Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
66 views
in Technique[技术] by (71.8m points)

javascript - How to find and solve an "Exception" error in google app script?

I have an app script that gets values from a spreed sheet and updates a Google forms. It was working normally until I did "SOMETHING?" and it all stopped working. I had to make a new one, that "works" but returns an error every time. How can I find and fix that error?

The Script:

const Tasks = () => {
  const GOOGLE_SHEET_NAME = 'Form Data';
  const GOOGLE_FORM_ID = '1m9Y78nRS-YjzwKS4Vpcy2JHvjuNYUzswAEmFDE-zIQo';

  const ss = SpreadsheetApp.getActiveSpreadsheet();

  const [header, ...data] = ss
    .getSheetByName(GOOGLE_SHEET_NAME)
    .getDataRange()
    .getDisplayValues();

  const choices = {};
  header.forEach((title, i) => {
    choices[title] = data.map((d) => d[i]).filter((e) => e);
  });

  FormApp.openById(GOOGLE_FORM_ID)
    .getItems()
    .map((item) => ({
      item,
      values: choices[item.getTitle()],
    }))
    .filter((values) => values)
    .forEach(({ item, values }) => {
      switch (item.getType()) {
        case FormApp.ItemType.CHECKBOX:
          item.asCheckboxItem().setChoiceValues(values);
          break;
        case FormApp.ItemType.LIST:
          item.asListItem().setChoiceValues(values);
          break;
        case FormApp.ItemType.MULTIPLE_CHOICE:
          item.asMultipleChoiceItem().setChoiceValues(values);
          break;
        default:
        // ignore item
      }
    });
  ss.toast('Update Finished!!');
};

What the Script pulls from the spreed sheet:

Nome de Mestre:
Akmusth
Bakon
Bill
Borges
Brun?o
Carlos André
Chris
Curvello
Danilo Carneiro
Douglas Bastos
Dudinha
Fragoso
Garrit
Genkai
Helton
John
Júnior Carvalho
Kobra
Léo
Liberal
Matheus Gravalos
Pedro Rolinsk
Pollux
Rafael Martins
Razec
Sh3ng
Tales Fox
Tatá
Tellindo
Thairony
Valber
Victor Hugo
Wesley Batista
Yami

The Error:

Exception: Invalid Argument: values (line 30, file "Tasks")

What I get at Stackdriver Logging:

Exception: invalid Argument: values
at unknown function
at Tasks(Tasks:24:6)

question from:https://stackoverflow.com/questions/65878176/how-to-find-and-solve-an-exception-error-in-google-app-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...