Global variables on a page

Hi,

I have had a look through the videos but can’t find one which addresses my issue.

I have a page with multiple buttons which will have a variable (level) set to a number when a button is pressed after which the app goes to page 2.

e.g.

Page 1

Button 1 sets ‘level’ to 1 → navigate to Page 2
Button 2 set ‘level’ to 2 → navigate to Page 2
etc.

So I am doing this for each button.

2024-11-04 20 10 44

On page 2, I want to retrieve the value of level and use it to display values on this pages buttons.

If value = 1

Set Button labels to 1-1. 1-2. 1-3, etc.

If value = 2
Set button labels 2-1, 2-2, 2-3, etc.

Not sure how to get the retrieval of the value of the variable done and the button labels set.

Any assistance would be appreciated.

Thanks
Steve

Hi Steve,

Here’s a video on how to use conditional logic in Codeless:

To get a value from App Data, use the Get property of block. Here are a few tutorials on how to work with object’s properties (App Data is also an object):

Regards,
Mark

Wow, that was impressively quick!!

Thanks very much Mark. Will have a look.

Steve

1 Like

Hi Mark,

I had a look at the videos and have made some progress.

2024-11-05 14 16 45

I used this to set the value in the App Data object and then used this

to retrieve the value and now I can do the if-then-else to run different blocks of code.

What I am stuck on now is how to change the text in a text block and on buttons dynamically.

From my understanding, data bindings for components (text, buttons, etc) can be only done with Page Data, so I created logic to move the data into Page Data.

How then do I get that binding done? I have realised that if I hover over the “data binding property name” section, it is disabled - I assume this is since there are logic blocks associated to the component.

Thanks
Steve

Hi Steve,

You’re making good progress.

Keep in mind that data binding in UI components works with a data model that is “assigned” to a component.

There are two ways to execute data binding:

  1. using a property name in the field right under “Content Logic”. In that case, when data is set to that property in the assigned data model (which is Page Data in your case), the content will be pulled automatically from the data model using the specified property.

or

  1. using logic (as you tried). In that case, you need to retrieve data from wherever it is. In your case, the data is in the App Data model, so what you want to do is use the “return” connector and return the result of the “get property of” block. In fact, you already use it, simply move “get property of” to the “result” connector and it should work.

Regards,
Mark

1 Like

Hi Mark,

So, as I can see, using method 1 which uses App Data precludes me from doing the binding in the Content Logic Box (since it only works with Page Data). Once I move the data App to Page using logic, the Content Logic Box is disabled.

In method 2, I have done a print on the second page and verified that I am getting the data but how do I push that retrieved data into the text block and/or button labels?

Steve

You have two options:

Option 1
In the event when the page loads, get the value from App Data and assign a property in Page Data. Use the same property name for Content Logic data binding

Option 2
Keep the value in App Data and create logic for Content Logic where you will extract the value for button’s label from App Data (as I described in the previous response).

1 Like

Hi,

When I hover over Content Logic I get a No Entry icon showing up and not allowed to type in anything.

This is because you added logic for “Content Logic”. You can have either logic or property name in the field, but not both. If you want to be able to enter a property name, you need to click the red “trashbin” icon to delete the logic.

Ok,

I found where I was going wrong. I was putting the logic which transferred the data from App Data to Page Data under the Text logic.

Lightbulb went off and I realised that it should be under the Page logic.

So, its working and onward I go!!

Thanks for your patience!

Steve

1 Like