Web Application - Calling Server Actions and getting its output from javascript

Web Application - Calling Server Actions and getting its output from javascript

  

Hi, I was wondering if in web application, we can call server actions from javascript and get its output.

In mobile application, this is possible to achieve : from Javascript, I can call Client Action that is calling Server Action inside its logic. Then, this Client Action will be treated as Javascript Promise object. For example,

var callClientAction = $actions.ClientAction1(inputA, inputB);

Promise.resolve(callClientAction).then(function(output) {

    // success and output is returned

}).catch(function(error){

   // error

});

I read other post, we can bind Server Action to hidden button, and trigger click event to call Server Action. But, what I need is also to get the output from Server Action in web application.

Please advise,

Thanks,

Solution

Hi Danang,

In your Screen action you can assign a value to a variable that is bound to an (hidden) Input widget. Then, refresh that Input widget and get its value using javascript.

Cheers,

José

Solution

José Costa wrote:

Hi Danang,

In your Screen action you can assign a value to a variable that is bound to an (hidden) Input widget. Then, refresh that Input widget and get its value using javascript.

Cheers,

José

Hi José, thanks for the reply,
One question, how do I know that Screen action execution has finished from javascript side?

I'm thinking that we could listen to onchange event on that hidden input widget, so when its value is refreshed, then we know Screen Action has already finished and do something to the output.

Thanks,

Danang


Hi Danang,

The onchange event is not caught in hidden input fields unless you explicitly triggers it.

So, in your screen action you could add a RunJavascript action to execute something like:

setTimeout(FunctionToTriggerEvent, 0);

Which will run all the events that it has to run and after that will run your FunctionToTriggerEvent. At that point the value should already be in input field (hopefully :) ).

Cheers,

José