HOW TO: Extract data from Google Sheets and get data rows into name/value pairs

Comments

2 comments

  • Official comment
    Scott Henderson CTO
    Celigo University Level 1: Skilled
    Answer Pro
    Top Contributor

    We published a brand new template in our marketplace that makes it super easy to work with Google Sheets. We published a new article too explaining all the details (here). Hope this helps.

  • Tyler Lamparter Principal Product Manager
    Awesome Follow-up
    Engaged
    Top Contributor
    Answer Pro
    Celigo University Level 4: Legendary

    Another way to do this and not hardcode your field names is to utilize this script. If you select row A when getting sheet data, you can have a pre save page script to transform the data and create the JSON fields using the first returned result.


    function preSavePage (options) {
      
      let output = [];
      for (let d of options.data) {
        let fields = d.values[0];
        for (let [index,r] of d.values.entries()) {
          if (index > 0) {
            let o = {};
            for (let [indexF,v] of r.entries()) {
              o[fields[indexF]] = v;
            }
            output.push(o);
          }
        }
      }
      
      return {
        data: output,
        errors: options.errors,
        abort: false,
        newErrorsAndRetryData: []
      }
    }
    0

Please sign in to leave a comment.