Transforming customer with multiple shipping address, and combining a field into a comma separate field

Comments

4 comments

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

    Raul Bernales now you're getting more complex on me and we can't use simple handlebar expressions here and will have to use a script.

     

    First, you'll need to enable grouping on your NetSuite export step, like so:

     

    Next, you'll need to create a preSavePage hook on the NetSuite export step and utilize this script:

    function preSavePage (options) {
      
      let output = [];
      for (let d of options.data) {
        
        //get the unique combinations of record id, address line 1, and country
        let uniqueCombinations = JSON.parse(JSON.stringify(d.filter(function (a) {
            var key = a["id"] + '|' + a["Address Line 1"] + '|' + a["Address Country"];
            if (!this[key]) {
                this[key] = true;
                return true;
            }
        }, Object.create(null))));
        
        //loop through the rows and concat pricing group to the unique combinations
        for (let u of uniqueCombinations) {
          u["Pricing Group"] = '';
          for (let r of d) {
            if (r.id == u.id & r["Address Line 1"] == u["Address Line 1"] && r["Address Country"] == u["Address Country"]) {
              if (u["Pricing Group"]) {
                u["Pricing Group"] = u["Pricing Group"] + ',' + r["Pricing Group"];
              } else {
                u["Pricing Group"] = r["Pricing Group"];
              }
            }
          }
          output.push(u);
        }
      }
      
      
      return {
        data: output,
        errors: options.errors,
        abort: false,
        newErrorsAndRetryData: []
      }
    }

    This should give you the following output:

     

    Since the grouping feature on the NetSuite export only allows grouping based on internal id, we had to do this. If we could have grouped on id, address line 1, and address country on the export settings, then we could have had a simple transform and handlebar expressions down the road.

    0
  • Raul Bernales
    Celigo University Level 2: Seasoned
    Engaged
    Awesome Follow-up

    Hi Tyler,

    I'm not sure if I was able to follow your instructions,  but I'm getting the error message below

    Message: TypeError: d.filter is not a function
    Location: <anonymous>:7
    Stack: TypeError: d.filter is not a function
        at preSavePage (<anonymous>:7:58)

    here is a screenshot for your reference.

    Thanks!

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

    Raul Bernales it looks like you didn't enable grouping on your NetSuite export. See the screenshot on my first comment. 

    0
  • Raul Bernales
    Celigo University Level 2: Seasoned
    Engaged
    Awesome Follow-up

    Hi Tyler,

    Finally, I was able to find time for this  and we got it working this time.  Thank you for all your help.

    Best regards,

    Raul

    1

Please sign in to leave a comment.