Camunda Embedded Forms

Can I fetch data from APIs in start form and use them in task forms without using API again?

Hi @shubh,

I am not sure, whether I understand your question correctly. Could you please elaborate on what you want to achieve? What is the use case? Do you use the tasklist?

Cheers,
Roman

1 Like

Ok i will show you a code-snippet from my HTML form.

inject([ā€™$scopeā€™, ā€˜$httpā€™, function($scope, $http){
camForm.on(ā€˜form-loadedā€™,function(){
$http.get(ā€œhttp://1**.1**.*.:31/read?table=TABLE1ā€).success(function(result){
$scope.dataList = result;
});
});
}]);

I used this code in my start formā€¦my question is if I can use this ā€œ$scope.dataListā€ variable in my further forms without hitting the URL again n againā€¦
If possible, how?

Every form has its own scope, so you would need to fetch it again for every form.

What you could do is fetch it in the start-form and store it somewhere globally, e.g. in localStorage or - if you are feeling really hacky - on the window object. You could then access it in every embedded form. But I would not recommend it :wink:

hey thanks for the quick reply sebastian.

Actually i have multiple forms and each form requires the multiple (same as previous form) URLs to be hit.

Can you elaborate as to how I can store it globally or on the window object through codeā€¦that would be great for me sebastian :slight_smile:

Do you want to avoid repeated requests in general or is it just that this particular request is expensive so that it should be performed only once per process instance (or similar)?

i want to avoid repeated requests in general.

Hm, ok, I am not a frontend engineer, but I have the impression that you are over-optimizing here. Anyway, perhaps @sebastian.stamm has some more ideas and the browser can cache some things away (e.g. using by using certain response headers such as https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Expires).

If I declare dataList variable like this ā€“
window.dataList;

Would it work on other forms?

No. You need to save the information you want to use in the rest of the process in Variables.
You generally share information belonging to the process in variables until ready to move to the Data Store when the process is done or needed.

I am a little bit confused now with all these varying answersā€¦

You could then access it via window.dataList in other forms, yes, but only until the user refreshes the page. So you would need to check if the variable is set and fetch it otherwise. Similarily when storing it in the localStorage.

In my opinion, storing it as a process variable as @lcrodriguez mentioned or performing the request for every form would be the easiest and most robust solution here.

ok thanks :slight_smile: