Advanced aggregation walkthrough

Last update: 2024-02-12
  • Created for:
  • Beginner
    User

Call a web service to return details about multiple countries and identify the total population of all countries, grouped by sub-region.

An image of the Fusion scenario

Advanced aggregation walkthrough

Workfront recommends watching the exercise walkthrough video before trying to recreate the exercise in your own environment.

 Transcript

The purpose of this next walkthrough exercise is to continue practicing with iteration and aggregation and also introduce you to advanced aggregation, where you use grouping features to produce more than one aggregate output. You don’t need any Google spreadsheets or your test drive instance for this walkthrough exercise, but on the next page in this training course, there are two URLs that you want to find below the training videos that you’ll use when building this scenario.

Let’s start this next walkthrough exercise by creating a new scenario and calling it Advanced Aggregation. For our trigger module, let’s use the make a request HTTP module For the URL, you can copy and paste the first URL listed below these training videos. We can leave it as a GET method and parse the response, and click OK. Let’s rename this module Get Countries. Now, let’s run this scenario one time to see what type of information we get back from the country’s API.

Opening the execution inspector, I can see that I received one bundle of information back and within the data array, I have 24 collections for 24 Spanish-speaking countries. Let’s use another make a request HTTP module to gather subregion information for each of the 24 countries. I’ll click Add Another Module, Make a Request, and then you can copy and paste the second URL listed below these training videos. For this API call to work, we need to use the country name at the end of the URL that we pasted in. If we go into the data array, we see the name listed at the top of that section, clicking it will add that item to our URL, but you’ll notice that the item has the number one after the data, meaning it’s only going to pull the first name listed in the Get Country data array. Let’s go ahead and parse this response and click OK for now, and we’ll rename the second module Get Country Details. Now, let’s run once again and see what information we receive back.

Opening the execution inspector for the second module, I see that I have, again, one bundle output, a data array, and only one data collection for the first country in the previous array. To fix this, we need to add an iterator between these two modules so that we can process each bundle in sequence. We’ll do that in the next video.

To add the iterator between our two modules, I’m going to right-click the dotted line between the two and select Add a Module. Search for iterator.

For the array field, we can pull the data array from our Get Countries Module, and click OK. Now that we’ve done that, we need to update our Get Country Details Module URL to not grab the single country name but rather each name in our iterator.

Go ahead and click OK.

Now that we’re iterating for each country and getting that country information, we’re going to close the loop and add an aggregator at the end. Click the Add Another Module, and find the numeric aggregator.

For the source module, we’re going to choose our iterator.

For our aggregate function, we’re going to choose SUM, and our value is going to be the population contained within our Get Country Details Module and the data array.

What we’ll receive at this point is a single bundle output which is going to be the aggregate sum of all the populations of all the countries that we’re processing, but we want to use the advanced settings on our numeric aggregator to further group the populations by subregion. Again, you can find this in the Get Country Details below the data array.

Go ahead and click OK. Because we chose to group within the numeric aggregator, we’re now going to have multiple bundle outputs. To aggregate that into a single output with the summed information for each sub-region, let’s add a text aggregator at the end.

To finish our scenario, let’s add a text aggregator to combine all of the information from the groupings we used in our numeric aggregator. To do that, I’ll click Add Another Module, and add the text aggregator. For the source module, I’m going to choose our numeric aggregator, and for the text, I’m going to type out the total population of, what I’ll put next is the key or the grouping of our subregion. Then I’ll type is, and I’ll use the result or the total population for that subregion. Go ahead and click OK. Now, let’s run the scenario and see what the output is at the end.

If I look into the execution inspector on our text aggregator, I’ll see that we have in fact created a sentence for the total population of South America is this large number, and then we go into our next sentence, the total population of Central America is another number. If I want to make this a cleaner output that I could potentially email or post somewhere, let’s go ahead and return back into our text aggregator and at the end of our sentence, under the text and binary functions, let’s add two new line keywords.

Go ahead and click OK, and then run your scenario again.

Looking into the execution inspector one more time, we’ll now see that we have our seven bundle inputs and our output, if we expand it, is seven different sentences all in one paragraph separated by a paragraph break. -

Exercise URLs

  • https://restcountries.com/v2/lang/es
  • https://restcountries.com/v2/name/{country name}

Reinforcement of aggregation principle

Any time a module outputs multiple bundles, every module after that will execute each bundle.

To prevent this, add an aggregator after a module that potentially produces multiple bundles.

You’ll see a shadow surrounding any segment in your scenario from a beginning-iterator to the ending-aggregator. This helps make these segments easy to spot in your Workfront Fusion scenario.

Your turn

NOTE

Practice exercises and challenges are optional and are not necessary to complete Fusion training.

This practice exercise builds on what you learned in the walkthrough, but the solution is not provided.

Create a new scenario to sum all hours logged on tasks in projects in the marketing portfolio. Then send one email that says “Your {Project Name} project team has logged {summed hours} of the total {planned hours} planned hours, putting you at {percentage} of the plan.”

Challenge: See if you can do the same thing but for hours logged this year only.

Want to learn more? We recommend the following:

Workfront Fusion documentation

On this page