How to get back the rest API call from a fragment


My question is on the UI Designer.
I have a list of lines.
On each line, the user gives some values (categories).
From these values, I need to call a REST API to get the price of the benefit according to values. This cost
must be displayed in the line and send back to the server.

With the UI Designer, it is not possible to call a REST API per line, so I created a fragment. In the
fragment, I get the line in parameter, and I call the REST API when values change. The name of my rest
API variable is "cost";.

Question: how do I send back this "cost" to the parent form?
Cost is a REST API and cannot be exposed.
So I created a JavaScript variable "saveTheCost";, with the value
$data.line.cost = $data.cost;
return "ThisValueIsNotUse";

Is that the correct way? Is my JavaScript will be called every time when the cost change (because
"saveTheCost" is not used, not displayed).
Thank you for your return.


Submitted by Dibyajit.Roy on Fri, 07/23/2021 - 15:16

This is how I would be doing the same.
First you must have a collection. Your fragment will be placed inside this collection. Lets call the collection as formInput.myItems.
Now each row inside the fragment would be referred as $item
if you set a value as $item.cost inside your javascript.
In the main page, if you check formInput.myItems , it should contain $item.cost with different cost values for each row.


No answers yet.