apply if statement for container visibility out systems.

apply if statement for container visibility out systems.

  

So , I  have  data which have interestId and userID. So I want to display a container (through visibility feature) which iterates through a list if it has matching value in another list. So , for example , visibility should do something like this  

visibility = ( if (GetInterests.List.Current.UserInterests.Interesttd).Exists and (GetInterests.List.Current.UserInterests.UserId).Exists) , so if both current id's exists , the value of visibilty should be true else false . So how do I do this in expression Editor of Visibility feature of container ?

Put you condition in DIsplay property of container

eg:if (GetInterests.List.Current.UserInterests.Interesttd <> NullIdentifier() and GetInterests.List.Current.UserInterests.UserId <>  NullIdentifier(),True,False)

Hi Gagan,


You can do like Amreen wrote, but for more best practice and clean code you just need to write in the display property of container: "GetInterests.List.Current.UserInterests.Interesttd <> NullIdentifier() and GetInterests.List.Current.UserInterests.UserId <>  NullIdentifier()".


You don't need to enclose in if because you're testing already true situation.

Hope this can help you.

Best regards,

Ricardo

let me re-iterate the question . So , what if I have 4,5 values in current row in list A. how do i check that 4,5 also exists somewhere in single row in list B

Hi Gagan,

You can also check with that condition if your first list current value is equal to second list current value (4,5 of A = 4,5 of B) is satisfied the condition then Display otherwise not. 

GetListRecord1.List.Current.UserInterests.Interesttd  = GetListRecord2.List.Current.UserInterests.UserId


-Hitesh

Hi Gagan Chohan,

That's an entirely different question. May I ask for an example scenario where this would make sense for you?

For this second question, you will likely to have to query the database, you cannot iterate two lists at the same time/pace:

  1. you can do it by creating an Action ExistsInB
  2. setting its Function property to true and set it's output parameter to be a boolean
  3. The action's logic would query the database to see if there is any record in Entity B with attributes InterestId and UserId set to the values you want (received as input parameters).
  4. set the output parameter to true if you found a record.

Then, in your container's Visible property, add a call to your function after the existing checks: "GetInterests.List.Current.UserInterests.Interesttd <> NullIdentifier() and GetInterests.List.Current.UserInterests.UserId <>  NullIdentifier() and ExistsInB(GetInterests.List.Current.UserInterests.Interesttd, GetInterests.List.Current.UserInterests.UserId)"

Jorge Martins wrote:

Hi , 

  I followed your steps and created a server action ExistsInB , but when I try to assign it to "Visible " of container , it doesn't show up in dropdown list of expression editor . 

Hi Gagan Chohan,

That's an entirely different question. May I ask for an example scenario where this would make sense for you?

For this second question, you will likely to have to query the database, you cannot iterate two lists at the same time/pace:

  1. you can do it by creating an Action ExistsInB
  2. setting its Function property to true and set it's output parameter to be a boolean
  3. The action's logic would query the database to see if there is any record in Entity B with attributes InterestId and UserId set to the values you want (received as input parameters).
  4. set the output parameter to true if you found a record.

Then, in your container's Visible property, add a call to your function after the existing checks: "GetInterests.List.Current.UserInterests.Interesttd <> NullIdentifier() and GetInterests.List.Current.UserInterests.UserId <>  NullIdentifier() and ExistsInB(GetInterests.List.Current.UserInterests.Interesttd, GetInterests.List.Current.UserInterests.UserId)"



Hi Gagan Chohan,

The dropdown list of an Expression only shows suggestions, if you open the Expression Editor, you will find your Server Action under the User Functions folder (on the bottom left tree). Alternatively, you can just copy & paste what I placed between " " in my answer (or use the code below):

GetInterests.List.Current.UserInterests.InterestId <> NullIdentifier() and GetInterests.List.Current.UserInterests.UserId <>  NullIdentifier() and ExistsInB(GetInterests.List.Current.UserInterests.InterestId, GetInterests.List.Current.UserInterests.UserId)

Note: I fixed Interesttd with InterestId on the code above (assumed it was a typo in the original post and was supposed to be an Id, if that is not the case, just fix it back).


Hi , 

    just to make sure We are on same page , I am trying to add a serverAction ExistsinB for visibility property . I can't see server actions in user Functions and in other post too that I posted , someone said that it's not possible to use serverAction . https://www.outsystems.com/forums/discussion/42688/server-action-for-visible-property-of-a-container/?utm_source=community&utm_medium=email&utm_campaign=forum-reply=#Post153795

Jorge Martins wrote:

Hi , 

    just to make sure We are on same page , I am trying to add a serverAction ExistsinB for visibility property . I can't see server actions in user Functions and in other post too that I posted , someone said that it's not possible to use serverAction . https://www.outsystems.com/forums/discussion/42688/server-action-for-visible-property-of-a-container/?utm_source=community&utm_medium=email&utm_campaign=forum-reply=#Post153795

Hi Gagan Chohan,

The dropdown list of an Expression only shows suggestions, if you open the Expression Editor, you will find your Server Action under the User Functions folder (on the bottom left tree). Alternatively, you can just copy & paste what I placed between " " in my answer (or use the code below):

GetInterests.List.Current.UserInterests.InterestId <> NullIdentifier() and GetInterests.List.Current.UserInterests.UserId <>  NullIdentifier() and ExistsInB(GetInterests.List.Current.UserInterests.InterestId, GetInterests.List.Current.UserInterests.UserId)

Note: I fixed Interesttd with InterestId on the code above (assumed it was a typo in the original post and was supposed to be an Id, if that is not the case, just fix it back).




Jorge Martins wrote:

For this second question, you will likely to have to query the database, you cannot iterate two lists at the same time/pace:

  1. you can do it by creating an Action ExistsInB
  2. setting its Function property to true and set it's output parameter to be a boolean
  3. The action's logic would query the database to see if there is any record in Entity B with attributes InterestId and UserId set to the values you want (received as input parameters).
  4. set the output parameter to true if you found a record.

You can make any Server Action a Function (showing in Expression Editor), if you set the Server Action's Function property to True/Yes, like I mentioned in my instructions.


Jorge Martins wrote:

   Thanks for fast reply . I actually made that function property true. After taking screenshot , I even changed the public to Yes . Same result

Jorge Martins wrote:

For this second question, you will likely to have to query the database, you cannot iterate two lists at the same time/pace:

  1. you can do it by creating an Action ExistsInB
  2. setting its Function property to true and set it's output parameter to be a boolean
  3. The action's logic would query the database to see if there is any record in Entity B with attributes InterestId and UserId set to the values you want (received as input parameters).
  4. set the output parameter to true if you found a record.

You can make any Server Action a Function (showing in Expression Editor), if you set the Server Action's Function property to True/Yes, like I mentioned in my instructions.




Hi Gagan Chohan,

You failed to mention (or I didn't notice it?) that you were developing a mobile app.

In that case Kilian's remark is correct, you cannot call a Server Action from a Client Function.

What you can do is have a Client Action ClientExistsInB call your ServerExistsInB Server Action, and assign the output of ServerExistsInB to a variable (say IsVisible) that you use on the Visible property of the Container. Whenever you call your ClientExistsInB, it will refresh the Container (because it changed the value of IsVisible and its value is being used on the Container).

I have to say your follow up question seems a very academic one, do you have an actual requirement for something like this? I'd say it is typically solved by getting extra data from the server when we fetch the initial list (either by building a more complicated query or by using a Data Action.