Group Multiple Records

Comments

3 comments

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

    Dave Guderian you would need to use a preSavePage script because the Salesforce export does not have a group by feature just yet (like S3, FTP, HTTP connectors have). However, I'll caution it may not work 100% of the time and to avoid the chance of it not working sometimes, you will need to set a high page size on your export. The reason for this is that if you have 2 records that need to group together, but 1 record gets on page 1 and the other record gets on page 2, you won't be able to group them because the preSavePage script runs on a single page of data. As usual now, I use Celigo AI to build the script for me. Here is the output, script itself, and prompt used to create it.

     

    Script:

    function preSavePage(options) {
      // sample code that simply passes on what has been exported
      let groupedData = {};
      options.data.forEach(record => {
        const name = record.Name;
        if (!groupedData[name]) {
          groupedData[name] = {
            Name: name,
            plans: []
          };
        }
        groupedData[name].plans.push(record);
      });

      return {
        data: Object.values(groupedData),
        errors: options.errors,
        abort: false,
        newErrorsAndRetryData: []
      };
    }

     

    Prompt:

    Can you group objects in the data array together that have the same name? The output per group should look like this: {Name: value, plans:[{},{},...]}

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

    Dave Guderian if you want a 100% fullproof way, then you can export the data to a file provider, such as S3, FTP, etc, then have another flow to run after the first flow that picks up that file, groups how you need, then does whatever you want. See S3 export example below:

    0
  • Dave Guderian
    Engaged
    Celigo University Level 4: Legendary
    Awesome Follow-up

    Thank you Tyler. I am going to look at option #2 more this week! Thanks as always for the feedback!

    0

Please sign in to leave a comment.