cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Date and Time in Patch and collect function

Hi Experts,

I have date picker for date and for time I have used dropdowns. Now I need to send those data into collect and patch function 

Here my code-

date.PNG

What I was thinking is taking that date into label named dateandtime as shown in above image and sending that label into patch and collect function.

But how to pass it-

Can I use just dateandtime? It is not giving me error in patch function but in Collect it is throwing error. 

Tejasvi_munge_1-1593439940236.png

 

 

 

How can I date with time without error?

Any help is appreciated!

 

7 REPLIES 7
wyotim
Resident Rockstar
Resident Rockstar

Hey @Anonymous, I think one issue might be that you seem to be missing the ".Text" portion on the Dateandtime reference. Essentially, it is referencing the control itself and not the text value of the control. So it should probably be:

... journeystartdateandtime: Dateandtime.Text});
...

 

This is assuming that your data source will take this value as text and doesn't need it to be an actual datetime value. There will likely be an error saying it was expecting a datetime value but received a text value if that is the case. If it needs to be a datetime value, you would probably need to remove the "Time" text from the front and format the resulting text as datetime. Here is one way you could do that:

... journeystartdateandtime: DateTimeValue(Substitute(Label1.Text, "Time", ""))});
...

 

Basically, the substitute function replaces the text "Time" with nothing (""), and the DateTimeValue function formats the rest as a datetime value (unsurprisingly). 

 

Hopefully, that helps! Let me know if it does or doesn't sort things out; I'm happy to follow up if needed!

Anonymous
Not applicable

Hi @wyotim ,
Thanks for the response!
My data source needs it to be date an time value so it won't text. I have tried second approach- created one label as shown below

Tejasvi_munge_0-1593491800349.png

but it is not working in collect function

Tejasvi_munge_1-1593491946955.png

Am I missing anything?

 

 

wyotim
Resident Rockstar
Resident Rockstar

@Anonymous Rather than making a new label that holds that formula, you should actually put the formula in your Patch and Collect statements where the reference for that label is. So, where you currently have 'Journeydateandtime' in those formulas, put:

DateTimeValue(Substitute(Dateandtime.Text, "Time", ""))})


I hope that makes sense. Basically, you don't need to have another label; you can reference the one you already have and let the formula above take care of the formatting. Let me know if that does what you need or not!

Anonymous
Not applicable

HI @wyotim ,

Sure will try. Also, I have toggle buttons here in powerapps which has "two options " datatypes in CDS entity. How can I use that in collect. I have used Toggle1.Value but it throws error saying invalid argument in collect. How can i do that?

 

wyotim
Resident Rockstar
Resident Rockstar

@Anonymous Unfortunately, I don't have much experience at all with CDS; the company I work for primarily uses Azure SQL.

 

I was able to find a blog post that referred to the Two Option data type. While it seems to work similar to a boolean field, it looks like it needs the actual item value used in CDS. Here is a link to that article. The relevant info I was looking at is under the heading "Writing Changes", near the bottom of that section. This article is from 2018 and about an experimental feature that doesn't seem to exist now, so I am assuming it was rolled out. 

 

So instead of 'Toggle1.Value', maybe having a statement like:

If(
    Toggle1.Value = true,
    TrueItem,
    FalseItem
)

where TrueItem and FalseItem are the actual values for the Two Option data. 

If that doesn't work, we may need to track down someone with more CDS experience than me to help with that part. Let me know how it goes and we'll proceed from there!

Anonymous
Not applicable

Hi @wyotim ,

Thanks for the response.

I have tried that already not working. Even I tried using variable. Any other thing which I can try?  

wyotim
Resident Rockstar
Resident Rockstar

@Anonymous I found this forum post that will hopefully be of use to you. It looks like there is a different kind of syntax with the Two Option data type. Here is the way it was done in the solution post:

// Their example:
If(Toggle1.Value=true, 'IsOverdue (TaskLists)'.Yes, 'IsOverdue (TaskLists)'.No)

// In general terms:
If(Toggle1.Value=true, 'FieldName (EntityName)'.TrueValue, 'FieldName (EntityName)'.FalseValue)


Again, being a SQL guy, this is a bit out of my expertise but, hopefully, this example and that forum post get you where you need to be! 

Helpful resources

Announcements
Power Platform Call June 2022 768x460.png

Power Platform Community Call

Join us for the next call on August 17, 2022 at 8am PDT.

Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

Users online (3,535)