Hey Sven,
Happy to hear that you managed to configure M10074 and M7899 to send API calls
I understood that you want to achieve the following:
- Send a call with multiple products in the body
- Send multiple calls per product
- Optional: View a history of all sent calls/products at the product/call
To send the calls, we will do the following:
- Determine the list of products to be sent
- Pass the list of products to “N_CallTemplate - Build, Execute, Process Call”
- Build the body based on the “products” parameter.
- Send a test call
Send a products calls
1. Determine the list of products to be sent
Write a custom expression that returns the list of products that you want to send. For example:
{products, this, status.id.equals(1)}
Customize your expression with the help of the expression debugger until the list contains only the products that you want to send.
2. Pass the list of products to “N_CallTemplate - Build, Execute, Process Call”
In order to send a call where the body contains 1 or more products, you have to pass the custom list of products to the process “N_CallTemplate - Build, Execute, Process Call”. This process is produced in M7899. It is the same process that is also behind the “Execute call” Test button on the page of the call collection.
“N_CallTemplate - Build, Execute, Process Call” has the following input parameters:
1. Call template: Pass the correct call template to the process. The call template should have an export definition or a data definition set to create the body that contains the product data.
2. Call account: Pass the correct call account that matches the call template, or leave it empty if you have properly linked the template to an account.
3. Parameters: This is a list of tuples that are used for multiple purposes, depending on the configuration of the call template. We will use this multipurpose parameter to pass your list of products.
The tuple list needs to have the following format:
[<“key”, value >, <“key2”, value2 >].
In your case, the tuple should contain a “products” key with the whole list as the value. This looks like this:
[<“products”, {products, this, status.id.equals(1)} >].
4. Call: This is an optional parameter that we won’t use in this example.
3. Build the body based on the “products” parameter.
You probably have defined a data definition to create a JSON body for the products.
- Open this data definition
- Add a new data definition parameter “products” to use it within your data definition:
- Place %products at the right data definition field to use it as a filter expression. For example, “this.in(%products)”
- The data definition parameter is automatically filled with the list of products that you determined in step 1 when you send a call.
- To test out whether the body is created properly, go to the call template collection and execute your call template. Do not forget to enter your custom parameter similar to the one below
[<“products”, {products, this, status.id.equals(1)} >]
4. Schedule the execution of the call
You can either call this process in a workflow, as a scheduled task or in your custom component.
I would recommend using scheduled task for debugging, as they can be configured/tested without having to wait for an update. To do so, follow these instructions: How to add a new scheduled task (geplande taak)
If you have any questions, feel free to ask.
Optional: View a history of all sent calls at the product
You might want to see a grid of all calls that have been executed for a product in a grid on the product page and vice versa, a grid with all products that are contained in a single call.
This is somewhat similar to what I built recently in M10355. You can open the component for inspiration. The difference here is that I do not have a many-to-many relationship between the call and the record to send. I have used a one-to-many relationship where each record has one call, but 1 call can contain multiple records.
You have to do the following:
- Create a new process to link a list of products to a new call (required for many-to-many)
- Add a products grid at the call page and a calls grid at the product page
- Execute the process for linking before building the body
- Send a test call
- View the list of calls that have been executed per product
1. Create a new process to link a list of products to a new call
To be able to show the history, we need to create a new record for linking the custom list of products to a new call. A “product call link” is a new record with only two fields. A search link to link a N_Product and a search link to link a N_Call.The records that we want to add should look like this:
Then, build a new process to generate these records:
Process name: N_Call - Link products based on parameters
Input parameters:
- “call” of type N_Call
- “parameters” of type “List<tuple<string, mixed>>” (Do not deviate from this name and type!)
Return parameters:
- Success of type boolean
- Error of type messages
The process should look something like this:
This process extracts your custom list of products from the “parameter” with the “TupleExtLookup” action (tuple extensions plugin) and then loops through your list of products. For each product, we will add a new record called “Product-call link” to the database, if it does not exist yet.
2. Add a products grid at the call page and a calls grid at the product page
- At the virtual page of the N_Call record, add a grid of products to a new tabbed panel within in your custom component. This way you can see which product where part of a call.
- Add the following filtering to the grid:
this.in({ productcalllinks, this.product, this.call.equals(parent) })
- At the virtual page of the N_Product record, add a grid of calls to a new tabbed panel within in your custom component. This way you can see which calls were sent for a product call.
- Add the following filtering to the grid:
this.in({ productcalllinks, this.call, this.product.equals(parent) })
- Deploy your component and also add “M10388 - Novulo Call template processes” to the composition, if you haven’t yet, for the next steps.
3. Execute the process for linking before building the call
Make sure that “M10388 - Novulo Call template processes” is part of your application.
Call template processes allow you to execute a custom process before/after building/processing a call. In our case, we will configure the execution of “N_Call - Link products based on parameters” right before building the body. This will create all “Product-Call Links” for the call that is beeing executed.
-
Go to all settings > Process action definitions.
-
Add a new process action definition for your custom process, like so:
(1) Choose a proper description
(2) If you have updated your application with the component that contains “N_Call - Link products based on parameters” your process should be available here as “n_call_link_products_based_on_parameters_…”
(3) Click this button to ensure that the parameters are loaded
(4) Double check that both parameters are there, as you defined the in step 3 -
Open your call template
-
Navigate to the grid “Call template processes”
-
Add a new call template process:
(1) Choose the trigger moment “Before building call”
(2) Chose the process action definition that we defined in the previous step
(3) Leave this as “true” for now. -
Open the parameter “call” and fill in “this” as an expression. Save it.
-
We do not need to fill in anything for “parameters” because process parameters with the name ‘parameters’ and the return type ‘[<string,mixed>]’ cannot be defined manually. They are automatically set to the same ‘parameters’ as the parent process ‘N_CallTemplate - Build, Execute, Process Call’.
4. Send a test call
To test out whether “N_Call - Link products based on parameters” is executed properly, go to the call template collection and execute your call template. Do not forget to enter a parameter similar to this one
[<“products”, {products, this, status.id.equals(1)} >]
Double check whether, at the new call that you just created, the grid of “Products” is filled.
Also double check whether, at the page of the products that you just sent, the grid of “Calls” is filled.