13
Views
8
Comments
Solved
Pass data from parent web block to child web block
Application Type
Reactive

Hi All

In my reactive application, I have to pass set of values based on conditions (set of values differs using conditions), from my parent web block to child web block. How can I achieve this?

Rank: #67
Solution

Hi Kavya,


It works the same way as passing inputs from a screen to a block.

For instance in this example, I have the ChildBlock inside the ParentBlock and I'm passing a value dependent on a condition using an If. You can adapt the If and the example to your needs.


Regards,
João

Rank: #3039

Thanks Joao. But in some conditions my input would consist of three parameters and in some conditions my input parameter to the child web block would be only 2. How can I handle this situation?

Rank: #67

Hi Kavya,


You can have for instance, 6 parameters:

  • IsSituation1 - Boolean - that you will use on your block to know if you should use the first two parameters for situation 1 or the other 3 parameters for Situation2;
  • Parameter 1 for Situation 1
  • Parameter 2 for Situtation 1
  • Parameter 1 for Situtation 2
  • Parameter 2 for Situtation 2
  • Parameter 3 for Situtation 2


Or you can have two blocks: one for situation 1 and one for situation 2 and in your parent webblock you have an If to show Block Situation 1 or Block Situation 2. The if would be the condition to show one block or the other:


Bottom line, there are several ways of achieving this, you can pick the one that makes more sense for your use case.


Regards,
João

Rank: #3039

Thanks Joao. I have a single child web block and have to pass different parameters into the same. Is it possible? 

Rank: #67

Yes, in that case you can use the first approach I mentioned, having all the parameters you need (for situation1 and 2) and a flag IsSituation1 (or a name that makes sense to you) so in the child, you know which parameters you should use.

Please refer to the OML in attachment.

ExampleBlockParentChild.oml

Rank: #3039

Thanks Joao. In this scenario, I have a local variable in parent web block and I'm passing different values in the variable according to if conditions. I pass this local variable into the child web block input parameter. I tried using switch in the on Parameters changed in child web block but the action is not performed. I tried the same with Onrender and Onready also but the action is not performed in these events. Is there any other way of doing this?

Rank: #67


Can you share your OML so I can take a look?

If you use these variables in queries, you will need to refresh those queries in the OnParametersChanged, Service Studio will warm you for that.

Rank: #3039