After reading this article you'll know:
What the mass mutate step is
Why you'd use the mass mutate step for inserting records
How to use the mass mutate step in your application
The mass mutate step can be found in the block store and is used to mass mutate data, this can be inserting-, upserting-, and deleting many records. To find the step go to the block store and search for 'mass', the mass mutate step should pop up.
View details followed by
Install block to install the block to the appropriate organization and application.
Once installed we can use the step in our application.
The following data models are pre-created to showcase what the step is about:
The above models form a questionnaire template, within this template we can then generate questionnaires using the mass mutate step.
Basically what we're doing in this use case is creating a questionnaire template with questions, then based on the number of employees in your employee model the template will be created a number of times with associated questions.
In this example, there's a handful of employees, but imagine if you have a huge enterprise and you need to create questionnaires for 20.000 employees. You can imagine that'd take quite some time by simply looping through that collection and then create the questionnaires plus the associated questions. A questionnaire that has 25 questions would result in half a million new records being created.
The power of mass mutate
The mass mutate makes the example above a lot faster, this step 'intercepts' the call to the database. So instead of doing a create half a million times, it'll save them up and then insert them in one go.
How does this work you might ask? This is the action that creates questionnaires based on the questionnaire template:
In the start step an input variables is created that's requires the 'id' of a questionnaire template.
We then create a normal variable that retrieves the object of the questionnaire template using a filter based on 'id' like so:
And another variable to get the number of employees:
The first step in the action is the mass mutate step. This step has no configuration required, it will actually work straight out of the box. Everything that happens in the step will be intercepted and inserted (or updated and/or deleted based what you want) in one go. Making the process of mass inserting a lot faster!
The next step is to loop through the employee collection like this:
After that we can create a questionnaire for each employee by adding a create step in the loop:
Still in this loop we'll have to add another loop that'll create a number of questions based on the question template model.
And then we create these questions every iteration by adding a second create step within this loop:
And that's all.
If we execute this action and we provide an 'id' of the questionnaire template we'll create questionnaires for all our employees. In this use case I only have 8 employees and 3 questions in my template but when I run the action via the playground we can see that they're being created with the associated questions.