0

I'm trying to create a registration form that can be imbedded into our club website for users to sign up to our sessions with.

I need the form to be updated via the back end database which i'll add triggers and data formating etc in due course.

My issue for now is the dates on sheets are displayed as i'd like "03-Jul" but once my script has run they appear on the form as a full date and timezone stamp. I'm sure i just need the script to treat the "date" as a string instead of a full date/time value. can anyone advise what to change in my script to achieve this please.

TIA

function main() {
    
      var labels = wsData.getRange(1,1,1,wsData.getLastColumn()).getValues()[0];
    
      labels.forEach(function(label,i){
        var options = wsData
                      .getRange(2, i + 1,wsData.getLastRow()-1,1)
                      .getValues()
                      .map(function(o){ return o[0] })
                      .filter(function(o){ return o !== "" });

        updateDropDownUsingTitle(label,options);
      });
    }
    
    function updateDropDownUsingTitle(title,values) {
    
      var items = form.getItems();
      var titles = items.map(function(item){
        return item.getTitle();
      });
    
      var pos = titles.indexOf(title);
      if(pos !== -1){
        var item = items[pos];
        var itemID = item.getId();
        updateDropDown(itemID,values);
      }
    }
    
    function updateDropDown(id,values){
      var item = form.getItemById(id);
     item.asListItem().setChoiceValues(values);
    }

enter image description here

1 Answer 1

0

Tl;Dr replace getValues() by getDisplayValues()

Explanation

  • getValues() returns JavaScript Date objects for cells having a date, time, date-time and duration value. The value show in your form is the default conversion of the Date object into a string.
  • getDisplayValues() returns the cell displayed value as string.

Related

1
  • Spot on!!! thanks, i knew it would be something simple :)
    – Lee Morris
    Jul 3, 2021 at 13:24

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.