0

Hey all I am at a loss and honestly don't know what is happening or why? My knowledge of javascript in general is not that great but I am learning.

I have a object that gets populated by a html document. In that document I have several checkboxes. Some checkboxes are important and they need a VALUE.

*
 * Krijg alle verdeler data uit het formulier
 * @param form
 * @return data object
 */
function getS627Data(form) {
  var data = {
    IngediendDoor: form.ingediendDoor,
    Specialiteit: form.specialiteit,
    Aan: form.aan,
    Post: form.post,
    Station: form.station,
    Aanvraag: form.aanvraag,
    Rubriek2ARMS: form.rubriek2ARMS,
    Rubriek2AAndere: form.rubriek2AAndere,
    AanvangDatum: form.aanvangDatum,
    AanvangUur: form.aanvangUur,
    EindDatum: form.eindDatum,
    EindUur: form.eindUur,
    MetOverdracht: form.metOverdracht,
    Lvhw: form.lvhw,
    NodigLvhw: form.nodigLvhw,
    NodigLvhwBis: form.nodigLvhwBis,
    NodigWl: form.nodigWl
  };

  return data;
}

So here I populate the object with keys and values

/*
 * Al de functionaliteit voor het verdeler formulier
 * @param form
 * @return succes of fail
 */
function writeVerdelerForm(form) {
  try {
    var data = this.getVerdelerData(form);

    if(data.MetOverdracht == NULL) { data.MetOverdracht = 'FALSE'; }
    if(data.Lvhw == NULL) { data.Lvhw = 'FALSE'; }

    var sheet = SpreadsheetApp.openById('xxxxxx');
    this.writeData(data, sheet);

    // finalizeer alle sheet gegevens en creeër dan een pdf
    SpreadsheetApp.flush();
    this.createPDF(sheet, "Verdeler " + data.Lijn, true);

    return this.success();

  } catch (error) {

    return error.toString();
  }
}

And here I tried to do the check to see if the two important keys and values are populated. If not i want to add FALSE to them. Yet they keep on beeing undefined if not checked in the html code.

Am i missing something along the way?

7
  • What is NULL? Is that similar to null? Commented Jan 16, 2020 at 20:19
  • bad habbits i brought along but if when changed to null it did not fix the issue Commented Jan 16, 2020 at 20:39
  • So put debugger; right before those statements and use your browsers debugger to inspect the variable. See what their values actually are. Commented Jan 16, 2020 at 20:43
  • debugger is not working (i believe google apps script does not allow it.) Commented Jan 16, 2020 at 20:57
  • 1
    Try js value coercion where undefined is coerced to false. if(!data.MetOverdracht) { data.MetOverdracht = false; } if(!data.Lvhw) { data.Lvhw = false; } Commented Jan 18, 2020 at 21:24

1 Answer 1

1

In JavaScript these are special values and should be lower case and unquoted.

null
false
true

In principle, equality tests should also always use === rather than == (which will attempt a type conversion if required).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.