So I created a logic to determine the visibility of a button. The logic involves taking data from two aggregates. At first I just implemented it as a condition in the visible attribute of the button. But I was told that, it is not the best practice. So I tried doing it in a client action and called it in the On Ready event. But then it said it would be better to call the action in on after fetch of the aggregates. But when I put the action in the on after fetch of an aggregate then it showed error for the other aggregat. So I tried to create a server action and then call the server action in a data action. But then also I was facing the same error of 2 data sources being used. So How can I convert this logic into a data action. Or is it ok if I put it in the visible attribute itself. It is a huge condition
( (GetMeetings.List.Current.Meeting.AssignedTo = NullIdentifier() and GetMeetings.List.Current.Meeting.Created_By = GetUserId()) or (GetMeetings.List.Current.Meeting.AssignedTo = GetEmployees.List.Current.Employee.Id) or (GetEmployees.List.Current.Employee.Role = GetMeetings.List.Current.Assignee.Role))
Hi @Rupika CSo as far as I understand you have table-1 & tabel-2; your validation of visibility depends on both tables data.Here's what you can do :Approach-1:User Data Action 1- Create a data action 2- fetch both aggregates3- prepare a boolean output param based on aggregate data 4- use the DataSource on button visibilityIf(PopulateStatusForButton.IsDataFetched,PopulateStatusForButton.Status,False)
----------------------------------------Approach-2:1- Add both aggregates to screen 2- Set Table-1 to be fetched at start3- Set Table-2 as onDemand4- Create OnAfterFetch Handler for Table-15- In the OnAfterFetch; call the aggregate of table-2 i.e ondemand :)6- Validate the result & set the local variable param7- This local var param can be set as defautl false & when your workflow runs it will set & show /hide button
----------------
Approach-31- Create a server action which will return you the Status for the visibility of button
Good Luck
Hi @Rupika C ,
Could you please explain your use case in more detail? It seems like you could join the two entities directly, which might eliminate the need for using two separate aggregates.
HI @Rupika C ,
Enclose the button in a If condition(with your visibility condition logic) instead of using visible property of the button.
For visibility logic building : call the two aggregates in Data Action and assign the YourVisibilityCondition value to data action out parameter.
If you don't want perform any action by the user till data action execution completed, you can enable a spinner in On Initialize Event handler and disable in data action onafterfetch event handler.
1. Create a Data Action named "EvaluateButtonVisibility".
2. Inside the Data Action:
a. Add two aggregates:
- GetMeetings (with your required filters)
- GetEmployees (with your required filters)
b. Create a local variable: IsButtonVisible (Boolean)
c. Add the logic using an If statement:
If ((GetMeetings.List.Current.Meeting.AssignedTo = NullIdentifier()
and GetMeetings.List.Current.Meeting.Created_By = GetUserId())
or (GetMeetings.List.Current.Meeting.AssignedTo = GetEmployees.List.Current.Employee.Id)
or (GetEmployees.List.Current.Employee.Role = GetMeetings.List.Current.Assignee.Role)
)
{
IsButtonVisible = True
}
else {
IsButtonVisible = False
d. Set this variable as the Output of the Data Action.
3. On the screen, bind the button's Visible property to:
EvaluateButtonVisibility
Thanks,
Senthil
Hi @Rupika C,
You can load the second aggregate (Meetings) on demand, making it dependent on the first one (Employees). For example, load the Employees aggregate at the start, then fetch the Meetings aggregate only when needed. After the Meetings aggregate is fetched, you can set the button's visibility using an If condition in its OnAfterFetch event.
Thanks.