How can I make the if work

Hello, 


What I try to achieve is that if there is no film title entered , a  input box is shown , then the data is fetched from the external api and then shown but the input box must be changed into the label.


Can someone help me figure out what the right expression in the if is. 


Roelof


Solution

Hi Roelof,

I would tentatively say that I'd use a variable that indicates the state of the screen: waiting for user input, fetching data, and displaying data. If the state is 'waiting for input", you display the input box, if the state is "fetching data" you display a "waiting" icon, and if the state is "displaying" you show the title. In the OnAfterBlur you change the state from "waiting for input" to "fetching data", and in a new Screen Action that's the On After Fetch of DataAction1 you again change it from "fetching" to "displaying".

Solution

Not sure if I got the question correctly but there is something you can do after the data is fetched here:


Say if there is data fetched, you can do call an action to update the If statement variable and the value for the label (well, expression).

Kilian Hekhuis wrote:

Hi Roelof,

I would tentatively say that I'd use a variable that indicates the state of the screen: waiting for user input, fetching data, and displaying data. If the state is 'waiting for input", you display the input box, if the state is "fetching data" you display a "waiting" icon, and if the state is "displaying" you show the title. In the OnAfterBlur you change the state from "waiting for input" to "fetching data", and in a new Screen Action that's the On After Fetch of DataAction1 you again change it from "fetching" to "displaying".


Is it correct I can use then a nested if then to make that work 

Yes, multiple Ifs are needed here, there's no equivalent to a "Switch" on a Screen. You can nest them (which is what I would do in this case), but you can also put them sequentially on the Screen, for each condition (and having a "False" that's empty).

Thanks, 


Time to try to make this idea work. I think it will costs me some time. 

Good luck :)

Kilian Hekhuis wrote:

Good luck :)

I hope you can help me one more time. I tried to make it work as you described but If I now enter a title nothing happens. What did I not understand well 


Hi Roelof,

You used the onblur. That means nothing will happen until the focus moves from the input box. Personally, I'd add a Button, and have that call the Screen Action, instead of the onblur.

oke, I will try that tomorrow. Now time to sleep.  I hope I may ask you then for help if I still cannot make things work.

Kilian Hekhuis wrote:

Hi Roelof,

You used the onblur. That means nothing will happen until the focus moves from the input box. Personally, I'd add a Button, and have that call the Screen Action, instead of the onblur.


I tried it now with a button and the status as a Static Entity and still the page does not change.

Can you take a look where I misunderstood you ?

Well, there's a couple of things wrong here:

  1. The "Status" Local Variable has type Text, instead of type Status Identifier. It should be changed, and the default value set to "Entities.Status.Waiting" (without the quotes; note you can easily select the value from the drop down).
  2. In SearchFilmOnClick, you assign the value "Status = "testEntities.Status.Retrieving"" to the Status Variable. However, that is a boolean, the result of comparing Status to a Text, which will return True or False. Unfortunately, Service Studio doesn't warn you here, and silently converts this to the Text "True" or "False". What you should assign, after the change described above, is "Entities.Status.Retrieving" (again without the quotes).
  3. In DataAction1OnAfterFetch, change the assign to "Entities.Status.Displaying" (no quotes).
  4. On the Screen, there's a Container that contains an If with condition "Status = Entities.Status.Waiting". However, if the condition is True, an image is displayed, but the image source is the result of the query (DataAction1.Film.PosterUrl), so it should only be displayed if the Status is Entities.Status.Displaying.

I've included a version of the Module that I think should work (though I can't test it currently). As a last remark, purely functionally, you might handle the case that the DataAction1 data fetch doesn't have any results, e.g. because the user made a typo or the movie doesn't exist.

Thanks, 


It still do not work perfectly. Nothing happens when the status is chancing to  displaying. 

I will try to find out why that happens but if you also have a hint there.

it looks the DataActiomAfterFetch does not refresh the screen but it looks wierd to place there again the data action because then I think I have made a loop.


if I get this all working , I will also think of a solution if nothing gets returned or that the user did not enter any text


I did some  debugging n setting a debug point on the .SearchFilmOnClick and that one worked perfectly

but the DataActionOnAfterFetch we set on the DataAction1 is never called. When I set there a break point and debug it nothing happens and I see the same screen as I see when I do not debug the code. 

So please help one more time. 

Hi Roelof,

Can you include the latest version of your Module?