70
Views
10
Comments
Call a webblock action by a promise
Question
Application Type
Reactive

This is the onready of the webblock and I am passing an action  by object to parent like this 


The save function contains:

$parameters.SaveFunction = $actions.Gravar;


Now I am trying to call this action from the parent in a promise like this:

And it works, the console.log is just triggered when the action from the webblock child reaches the end.

But... What I want to achieve also is to pass data from the action. Any ideas?

2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Can't  you pass the inputs as seperate parmeters on the event to the parent?

2024-01-05 16-00-17
Filipe Lourenço

I dont' want to create an event for that. I want to get data from the promise call

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Hi @Filipe Lourenço ,

you could make something work with the Array.every() notation.  

I can get that to work with a single parameter.

I think if it needs multiple parameters, maybe use serialize/deserialize ?

Dorine

2021-09-06 15-09-53
Dorine Boudry
 
MVP

see attached an example oml, using a single Json as vehicle to pass information from the screen as input to the block's action.

For a single input value, you can just use a basic data type as input and leave out the JSON serialize and deserialize.

Dorine

QDR_PassFunctionAsObject.oml
2024-01-05 16-00-17
Filipe Lourenço

But I want is to retrieve from webblock to parent and not 

contrary

2021-09-06 15-09-53
Dorine Boudry
 
MVP

not sure I understand, you want to execute a function inside the block from the screen, and that should return information from the block to the screen ??

So screen 'collects' information that is inside the block, at a time determined by the screen ??? is that it?

2021-09-06 15-09-53
Dorine Boudry
 
MVP

the most obvious is to use an event, like Daniel suggested.

Can you maybe explain the underlying use case, maybe there are other ways ?

2024-01-05 16-00-17
Filipe Lourenço

Yes but that involves to create another action in the parent to receive the event . I want in the resolve of the promise to catch data in the same parent action.

2021-09-06 15-09-53
Dorine Boudry
 
MVP

Ok,

I understand what you are trying to do, but not WHY.  Are the normal mechanisms of passing data around in Outsystems not covering what you want to do?  Why does your screen need to collect data from your block ?   Why can't you just have it come through an event and react to that ?  

 I get that this would mess up your flow a bit in the screen, having to split up your logic between kicking off the action to collect the data, and reacting to the data coming back, but that would be preferable over this trickery. 

We are entering the world of obscure tricks here, which is tough for people later to understand and maintain. 

See attached an oml, see demoblock2, the trick is to attach the data to some html element in the block, and pick that up inside the function you shared with the parent.  This is all very awkward, and some of the reasons why it is so awkward are :

  • you can't pass complex data types in and out of javascript nodes, so forced to serialize and deserialize
  • you can't directly access block data from inside a javascript node
  • you can call a block action from inside a javascript node, which can acces block data, but those don't have outputs
  • you can call a client aciton from inside a javascript node, which has outputs, but those again can not access the block data

So there's not a lot to work with here.

If you are going to do this type of thing, please make sure to isolate it properly (like maybe make a special helper webblock doing this).

Dorine

QDR_PassFunctionAsObject.oml
Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.