30
Views
7
Comments
Solved
Determine if a Date and Time already exist in variable

I have a variable called "NewAppointmentData_DateTime" which has two structure attributes assigned to it as such:


Next i have a series of buttons with each responsible for a 1/2 hour increment:

When a time slot button is clicked, a client action is called that has a ListAppend within it that writes that time to the variable.  


I'm trying to do two things: 

1 - Disable the time slot button if the time being selected already exists in the variable (therefore the 2nd "16:30:00" would not have been written"

2 - Modify style elements based on whether the time being selected already exists in the variable.

Any help is appreciated!

--Rick

Solution

So you have your selected dates list right?

you will use a list filter or list index,

for the list filter, if the list filter returns data it means it exists and you return the output that exists if it doesn't exist you return it doesn't exist. It is as simple as that. This will be used in a client function inside of the properties of the button

I am going to create a quick example.

Have you read all the other answers? no questions?


Have a look at the OML

The other way as a solution would be using the approach from @Vikas Sharma, we need to give credit as well ;) and I think it would be a better approach if we knew how are you developing.


Here in this function, you can see it is comparing if the datetime from the button is inside of the selected list

And on the button, I am using the function

Note: I am using static data you just need to adapt the logic... also, you cannot use list filter or list indexes inside of functions, so I had to use a for each.

Kind regards,

Márcio

testingbuttons.oml

Hey, you could have a client action checking if the date from that button is inside of the list, as you are using reactive (you didn't say anything on your question, you must) the function will be checked against the list you have of selected dates if it's selected or not, and you could use the same function to disable the button (you can see a enable button attribute on the button).

PS: Dont forget that you have to pass to the client function these input parameters, the date itself from the button and the list where you are keeping the values ;) Use the function to change the style on the style classes and on the enable property of the button itself

This solution can be used either for static content or list content...

I also advise you (I see you are new to outsystems) to follow the guided path in case you are not already doing it, it would be better for you if you dont have yet the basics.

I hope I am not saying anything wrong or complex, if that's the case please let us know.

Note: try to give more information next time, as I don't know where those values are coming from if you are saving values elsewhere (database/entities/memory?).

Kind regards,

Márcio

Hello, 

You need to use List Filter.

Now you need to disable those buttons before calling client action. For that you need to use  list filter in for each on Entities OnAfterFrtch action ( I am guessing those values are coming from entity). In list filter add the source same as the list show in screen shot above and add your condition ( to find out same value in the list ).

If Filtered list has data that means the current record is available in the list and use local variable to make it disable. 

Hope this works for you, let me know if you require further assistance. 

Komal

Champion

Hi,

Agree with Marico. In your case from where you are getting this list of time slots. Basic idea will be in this list of time slots you can add one more variable of boolean type lets say name is isSelected. Value of this variable will be false initially. Once user select any slot value will change to true. 

Now in UI you can check if isSelected is true then make it disable. 

regards

Thanks to each of you for replying.

Komal, I looked into list filter but was not able to get it to work given I need to check for two separate values....a date and time.  Can you post an example of a what the syntax would be for list filter for the two attributes I'm checking against:  Date and StartTime

What I'm trying to do in OS looks something like this in pseudo code:


IF ("09/21/2023" exists in NewAppointmentData_DateTime:Date AND "16:30:00" exists in NewAppointmentData_DateTime:StartTime, "exists!", "")


Solution

So you have your selected dates list right?

you will use a list filter or list index,

for the list filter, if the list filter returns data it means it exists and you return the output that exists if it doesn't exist you return it doesn't exist. It is as simple as that. This will be used in a client function inside of the properties of the button

I am going to create a quick example.

Have you read all the other answers? no questions?


Have a look at the OML

The other way as a solution would be using the approach from @Vikas Sharma, we need to give credit as well ;) and I think it would be a better approach if we knew how are you developing.


Here in this function, you can see it is comparing if the datetime from the button is inside of the selected list

And on the button, I am using the function

Note: I am using static data you just need to adapt the logic... also, you cannot use list filter or list indexes inside of functions, so I had to use a for each.

Kind regards,

Márcio

testingbuttons.oml

Thank you for the detailed example!  I'll recreate it my solution and let you know how i make out.  And I'm attempting to do this for reactive web.  Thanks!

That worked!  Thank you very much.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.