Handlebar Syntax Help

Comments

2 comments

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

    I don't see how this can be done with handlebars because you basically need to regroup your data. It looks like this data is coming from NetSuite, could you group the data on the NetSuite saved search side? If you can get one tracking number tied to the item fulfillment on the result, then you could group by item and sum quantity. If that's not possible, I made a pre save page script that you could utilize.

    function preSavePage (options) {
      
      let newData = [];
      for (let d of options.data) {
        
        //get a list of unique skus to later sum to
        let uniqueSKUs = [];
        for (let r of d) {
          if (uniqueSKUs.indexOf(r.ItemName) === -1) {
            uniqueSKUs.push(r.ItemName);
          }
        }
        
        let newRec = [];
        for (let s of uniqueSKUs) {
          let o = {};
          let c = 0;
          for (let r of d) {
            if (s == r.ItemName && c === 0) {
              o = JSON.parse(JSON.stringify(r));
              o.TrackingNumbers = [];
              o.TrackingNumbers.push(r.TrackingNumber);
              c++;
            } else if (s == r.ItemName && c > 0) {
              o.Quantity = (Number(o.Quantity)+Number(r.Quantity)).toFixed(0);
              if (o.TrackingNumbers.indexOf(r.TrackingNumber) === -1) {
                o.TrackingNumbers.push(r.TrackingNumber);
              }
            }
          }
          o.TrackingNumbers = o.TrackingNumbers.join(',');
          newRec.push(o);
        }
        
        newData.push(newRec);
      }
      
      return {
        data: newData,
        errors: options.errors,
        abort: false,
        newErrorsAndRetryData: []
      }
    }
  • Geoff Manning

    Thanks Tyler I will give that a shot. I was having some issues getting the Netsuite saved search to report out the data in a way I could use it. The package contents are a custom record type under the fulfillment record and getting all the data the way I wanted proved difficult. I will give the preSavePage a shot, thanks!

    0

Please sign in to leave a comment.