cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
mikerosoft_user
Frequent Visitor

Collect Toggle Switch Value write to dataverse Yes/No

As subject line states, I have a canvas app with a toggle switch (Toggle1) that I want to Collect() with a button and write the value to a dataverse table column (Col1) which is of type Yes/No

 

In the button 'OnSelect' field I enter:

 

`Collect(table, {Col1:Toggle1.Value})`

 

This returns the error:

 

"The function Collect has some invalid arguments. Incompatible type. The Col1 column in the data source  you're updating expects 'OptionSetValue' and you're using a 'Boolean' type. "

 

I've scoured the forums to no avail.

 

Thanks.

 

1 ACCEPTED SOLUTION

Accepted Solutions

 

If(Toggle1.Value=true, Patch(records, Defaults(records), {wasAnxious: 'wasAnxious (MyTables)'.Yes}), Patch(records, Defaults(records), {wasAnxious: 'wasAnxious (MyTables)'.No}) )

 

@mikerosoft_userplease try the following code as given below

Hope this works for you

 

Please Accept as Solution if it solves your question Or just give it a Thumbs Up if it is helpful because this can help others.

LinkedIn: https://www.linkedin.com/in/manan-malhotra-vfx/

Want to support me! Buy me a Cup of Coffee?

View solution in original post

6 REPLIES 6
Manan-Malhotra
Skilled Sharer
Skilled Sharer

In the button try

If(Toggle1.Value=true,Collect(table, {Col1:choicename.Yes),Collect(table, {Col1:choicename.No))

 

Choice name can be found in reference to below image example "aaaaaa" in this case

MananMalhotra_0-1664812212299.png

 

 

OR it can be found with reference to below image

MananMalhotra_1-1664812320210.png

 

`

mikerosoft_user_0-1664814231367.png

I'm not entirely sure what you mean by choice names. As in use the label under 'Choices'? Note that the real column name is displayed here instead of alias.

 

If(Toggle1.Value=true, Collect(table, {wasAnxious:Yes.Yes}),Collect(table, {wasAnxious:No.No}));

 This still results in an Error. 

If(Toggle1.Value=true, Collect(table, {wasAnxious(@table):Yes.Yes}),Collect(table, {wasAnxious(@table):No.No}));

In your case you will see a   name in this way "wasAnxious(@table)" where  you will get a wasAnxious(@table).yes or wasAnxious(@table).no

Please follow this syntax after using the following above name

If(Toggle1.Value=true,Collect(table, {Col1:choicename.Yes),Collect(table, {Col1:choicename.No))

 

I appreciate the help but it's just not working for me (totally new to powerapps). To reproduce the example verbatim:

my table is called : records

the column to update: wasAnxious

toggle switch name: Toggle1

And the create statement is placed in a button 'OnSelect' field.

 

I appreciate the help, and will mark as correct answer if I can get it to work. Thanks again.

 

jcfDaniel
Super User
Super User

Hi,

 

You say you want to collect the value and write it to a dataverse table. Is there a reason not to just write it to the table?

 

For a new record, try this is your button's OnSelect: Patch(records, Defaults(records), {wasAnxious: 'wasAnxious (MyTables)'.Yes})

 

To have the value depend on the toggle, you have the solution from @Manan-Malhotra :

 

If(Toggle1.Value=true, Patch(records, Defaults(records), {wasAnxious: 'wasAnxious (MyTables)'.Yes}), Patch(records, Defaults(records), {wasAnxious: 'wasAnxious (MyTables)'.No}) )


Regards. JD.

 

If(Toggle1.Value=true, Patch(records, Defaults(records), {wasAnxious: 'wasAnxious (MyTables)'.Yes}), Patch(records, Defaults(records), {wasAnxious: 'wasAnxious (MyTables)'.No}) )

 

@mikerosoft_userplease try the following code as given below

Hope this works for you

 

Please Accept as Solution if it solves your question Or just give it a Thumbs Up if it is helpful because this can help others.

LinkedIn: https://www.linkedin.com/in/manan-malhotra-vfx/

Want to support me! Buy me a Cup of Coffee?

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (6,509)