Storing SQL Query result into form variables

Storing SQL Query result into form variables

  

Hi,

I am working on the booking assignment from outsystems tutorial and I have executed a query that fetches the cheapest room  from table, i have to show that room number and its price in the form like in the image i have attached.

How to store the result of query into form variables and then use the form data to proceed next.??

Thanks in advance

Hi Usama,

In the form you set up an XY expression (after the Room Label) with the number of the room and the price (you get that from the Form variable) Then, after getting the Room in the SQL query you can have an assign that does this:

After that when you Ajax Refresh the form you will get the XY Expression filled with the correct values.

Cheers,

José

José Costa wrote:

Hi Usama,

In the form you set up an XY expression (after the Room Label) with the number of the room and the price (you get that from the Form variable) Then, after getting the Room in the SQL query you can have an assign that does this:

After that when you Ajax Refresh the form you will get the XY Expression filled with the correct values.

Cheers,

José

thankyou jose I understood that assign logic but sorry couldn't figure out how to show that room number and price in the expression that is recieving on button click from sql query? 



Usama Hassan wrote:

Do I have to place that assign statement after sql assignment  in the "GetAvailableRoom" Action or in the screen preparation of bookig details??

Hi Usama,

When you do the above assignments after the SQL query (in the GetAvailableRoom Action), you are assigning values to the variables of the form (BookingForm).

Inside the form you can have an expression to show the room number and price. Those values must come from the Form. Something like:

BookingForm.Record.Room.RoomNumber + " at " + BookingForm.Record.Room.Price + "$ per night" 

Then, after the assign, when you refresh the form you will refresh the XY Expression and it will get the values from the Form.

Tell me if you still have problems with this.

Cheers,

José


Hi jose, thanks for the help

But here is something wrong, assign statements are not working in booking form, The Room entity is not present for which the two assign statements are to be written and neither the "ROOM number" and "Price" are not the part of booking entity

Solution

Hi Usama,

Ok. We are getting there. :)

Just drag the entity Room into the GetBookingById of your Preparation. Then you will get the Room attributes automatically in the Form since the source of the Form is that aggregate.

Try it.

Cheers,

José

Solution

Hi jose,

Thanks that solved my problem :)

 but it is not saving the status in the bookings table when the booking is done.

Can u tell me where i am doing wrong?


Kind Regards


Hi Usama,

I would say that before doing the Update of the Record you are not changing the status of that record in the Form.

Therefore, use an Assign statement before the Update where you assign the Booking Status (of the Booking, of the BookingForm) to the value that you want.

As a general rule always do this when saving a record from a form:

  • Check the attributes that are in the Entity (that you are going to save) and are not in the screen's form.
  • For each one of those, if you need to change its value use an Assign statement (before the Entity Action to update the form) to explicitly set the value of that attribute in the form.

Cheers,

José

Hi Jose Costa,  Here I am not able to get assignment value for 3 variable. Can explaine, where exact can get the GetAvailbleRooms.List.Current.Room.Id, Price, Room Number .  Please.  Also, please check the two attachements, I am not able to get the room with price. Please help on this also, 


Thanks in advance,

Gangadhara.

José Costa wrote:

Hi Usama,

In the form you set up an XY expression (after the Room Label) with the number of the room and the price (you get that from the Form variable) Then, after getting the Room in the SQL query you can have an assign that does this:

After that when you Ajax Refresh the form you will get the XY Expression filled with the correct values.

Cheers,

José

thankyou jose I understood that assign logic but sorry couldn't figure out how to show that room number and price in the expression that is recieving on button click from sql query? 





Gangadhara,

The aggregate that is in the preparation must contain the booking and the room entities:

The booking form is then linked to the preparation composite record: 


The output of the advanced SQL is then assigned to the BookingForm.Record.Room which will then make all the Room fields that you need to display in the expressions inside the form available for you to work with.

Ouen