In my web application, the visibility of one of my menu items is dependent on some preparation logic in the LoginInfo web block at the top right of the page.  The logic in LoginInfo is working fine, but the menu item is not displaying as it should when logging in.  As soon as I do a page refresh or move to another page it displays correctly.  This suggests that the properties for the menu item are applied before the LoginInfo preparation is performed.

Is there a way to apply the LoginInfo logic before the properties of the menu item is applied, or some other solution to this problem ?

Cheers, Richard.

Hi Richard,


the reason for this is that web block preparation and rendering happens in the sequence they are placed on the screen, and after the preparation of the screen is finished.  So yes, your logic in your LoginInfo happens after the menu webblock has been built up.


Can you share a bit more about what you're trying to do, so we can help think of solutions.  For example, is there a reason why you have this logic in your LoginInfo webblock, could you replace it with logic in the Menu webblock ?


otherwise, a quick fix is put LoginInfo before Menu in your screens :-)


Dorine

Dorine Boudry wrote:

Hi Richard,


the reason for this is that web block preparation and rendering happens in the sequence they are placed on the screen, and after the preparation of the screen is finished.  So yes, your logic in your LoginInfo happens after the menu webblock has been built up.


Can you share a bit more about what you're trying to do, so we can help think of solutions.  For example, is there a reason why you have this logic in your LoginInfo webblock, could you replace it with logic in the Menu webblock ?


otherwise, a quick fix is put LoginInfo before Menu in your screens :-)


Dorine

Hi Dorine,

Thanks for your reply.  Moving the LoginInfo before the Menu on my screen wouldn't provide such a good UI so not really an option in that respect.  Nor can I move the logic in the LoginInfo web block to the Menu web block because the information gets displayed in the LoginInfo web block, so option is out too.

I decided to make the Menu Item always visible and depending on the information from the LoginInfo web block as to whether that Menu Item actually takes you to the destination screen or whether it remains on the current screen.

Cheers, Richard.

Hi Richard,


Why don't you create an action to get the data you need for booth web blocks and insert it in the web blocks directly?


Hope this can help.


Best regards,

Ricardo

Hi Richard,

I am just curious what is this 'preparation logic' of yours. I previously have built a menu with a heavy logic based on several policy tables that determines the access we have for a certain user. As soon as he logs, we are dynamically creating the menus he has access to. And this is done all in the preparation.

I wonder what is yours.

Regards,

JC

Hi Juan,


I was thinking in create an action to retrieve the needed data, place it in the used layout web block preparation, an assign that data to the correspondent web blocks (removing the data fetch from original web blocks preparations).


Best regards,

Ricardo

Juan Carlos Elorde wrote:

Hi Richard,

I am just curious what is this 'preparation logic' of yours. I previously have built a menu with a heavy logic based on several policy tables that determines the access we have for a certain user. As soon as he logs, we are dynamically creating the menus he has access to. And this is done all in the preparation.

I wonder what is yours.

Regards,

JC

Hi JC,

I am doing something very similar, in my case the logic is based on a list of accounts that get's displayed in the LoginInfo area.  I'm trying to avoid repeating the data retrieval in both the Menu web block and the LoginInfo web block as it is a little intensive performance wise.

Cheers, Richard.

Ricardo Pereira wrote:

Hi Juan,


I was thinking in create an action to retrieve the needed data, place it in the used layout web block preparation, an assign that data to the correspondent web blocks (removing the data fetch from original web blocks preparations).


Best regards,

Ricardo

Hi Ricardo,

Thanks for your suggestions.  Please can you explain what you mean when you say "assign that data to the correspondent web blocks (removing the data fetch from original web blocks preparations)".  Sounds like a promising solution but it is not clear to me how you would achieve this ?

Cheers, Richard.

Hi Richard,

If you remove your LoginInfo preparation you will need to get the data from other side. You can get that data from an action that you place in the layout web block preparation. That same action will retrieve the information that you need for preparing you menu items. In resume, all that you need is made inside that action, and, like web applications are synchronous, you will have the correct fill in your menus.


Hope this can help.

Best regards,

Ricardo


Hi Richard,

Complementing what Ricardo explained, since your Server Action was executed in the Preparation of the Layout Web Block its Output Parameters would be available to be passed as Input Parameters to any Web Block that is used on your Layout Web Block.

But I'm not sure how that works for Web Blocks that are placed inside Placeholders (and both your Menu and your LoginInfo Web Blocks are), as these will be rendered in the context of the Web Screen and not in the context of the Layout Web Block.

Ricardo Pereira wrote:

Hi Richard,

If you remove your LoginInfo preparation you will need to get the data from other side. You can get that data from an action that you place in the layout web block preparation. That same action will retrieve the information that you need for preparing you menu items. In resume, all that you need is made inside that action, and, like web applications are synchronous, you will have the correct fill in your menus.


Hope this can help.

Best regards,

Ricardo


I was thinking you don't need that much logic in the LoginInfo preparation as well. That is unless you need that much information for the LoginInfo.

I am pretty sure we called actions in the menu block customized CheckUserRole() for each of the group of menus we've got (using it on an IF). This way, depending on the roles or access the user got, it will show or not the menus applicable for the user. I am not sure if that is the best pattern but I don't think we've got another way. 

Regards,

JC


Juan Carlos Elorde wrote:

Ricardo Pereira wrote:

Hi Richard,

If you remove your LoginInfo preparation you will need to get the data from other side. You can get that data from an action that you place in the layout web block preparation. That same action will retrieve the information that you need for preparing you menu items. In resume, all that you need is made inside that action, and, like web applications are synchronous, you will have the correct fill in your menus.


Hope this can help.

Best regards,

Ricardo


I was thinking you don't need that much logic in the LoginInfo preparation as well. That is unless you need that much information for the LoginInfo.

I am pretty sure we called actions in the menu block customized CheckUserRole() for each of the group of menus we've got (using it on an IF). This way, depending on the roles or access the user got, it will show or not the menus applicable for the user. I am not sure if that is the best pattern but I don't think we've got another way. 

Regards,

JC



Hi Juan,

The solution that I approach is in the case you need to prepare some data. 

In case of roles verification normally I use the Check roles functions in the Visible or Enable property of the respective menu (something like the approach that you say).


Everything depends of what you need to do. :)


Best regards,

Ricardo

Ricardo,

The thing is our Roles isn't the roles that OS have but a table containing the policies to determine the users' roles. Same concept different data source.

But yes I agree. It really depends on what you really wanted to do.

Cheers,

JC

Jorge Martins wrote:

Hi Richard,

Complementing what Ricardo explained, since your Server Action was executed in the Preparation of the Layout Web Block its Output Parameters would be available to be passed as Input Parameters to any Web Block that is used on your Layout Web Block.

But I'm not sure how that works for Web Blocks that are placed inside Placeholders (and both your Menu and your LoginInfo Web Blocks are), as these will be rendered in the context of the Web Screen and not in the context of the Layout Web Block.

Hi Jorge,

I tried implementing through the preparation in the Layout web block but the local variables I created were not available to the Menu web block so I couldn't get it to work that way.  Good idea though !

Cheers, Richard.


Richard,

A Web Block does not have access to the parent's scope, so the Menu Web Block would not have access to any local variables of the Layout Web Block nor the Web Screen's (the actual parent scope)...

A possible solution, is for you to slightly modify the Layout block and place the Menu block directly on the Layout block (and not inside the Menu placeholder of the Layout block). That way the Layout block can pass input parameters to the Menu block, based on data fetched from the Layout's Preparation.

There's always another solution, which would be using events, either via the Event System component or via platform events (in this case this would likely be less streamlined and more fragile).

Hope this helps!