A very common question asked both on the EasyMorph Community and to our support email is about whether it is possible to set the value of a parameter mid workflow.
Most people go looking for a “Modify parameter” action and find there isn’t one. That’s because parameters are immutable once the workflow begins. However, this doesn’t mean you can’t achieve what you want, it just means you need to split the workflow into a couple of modules.
Let’s imagine a theoretical scenario: I want to calculate the most sold product; then get all sales records for that product.
parameters.zip (184.5 KB)
The above example shows one way of solving this problem using parameters. The project contains 2 modules.
NOTE : Parameters are specific to a module and so the parameter needs to be created in our "Get Sales" module, not in our "Main" module.
The first module “Main” starts to process by querying the database for the most sold product. Although I could do this in a complex SQL query, I've kept it simple using EasyMorph actions instead so those who are not familiar with databases and SQL can also understand.
The steps used are as follows:
I like to think of our second module "Get Sales" as a helper module. In it we have a parameter called "ProductID" set to an initial value of "None"
The "Get Sales" module has a very simple workflow containing a single actions to load the data from the database where the "Product ID" field matches the parameter.
Running this module alone will not return any data as there are no records in the database where the product ID is equal to "None" (which we set as the initial value of our parameter). However, if we go back to the "Main" module and add an additional action "Call another module/project", we can call our "Get Sales" module, changing the value of the parameter and getting it to return the results back.
Note that we need to select the "First value of column" option to get EasyMorph to pass in to the parameter the value we calculated as the top selling product.
Although this example only calls our "Get Sales" module once, passing in a single value, it is also possible to repeat this action many times. If we wanted the sales for the top 3 products, we could modify our keep action to keep the top 3 rows, and then replace the "Call another module/project" action with the "Iterate" action.
This is just one example and this technique of calling other modules passing in parameter values can be used to solve lots of problems.