cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Julien2
Post Prodigy
Post Prodigy

Adaptive Card - Store Choices Options in SQL Server

Hello,

I have a flow that will store data in SQL Server after the user has filled the form on Microsft Teams. Inside the "Post an Adaptive Card to a Teams channel and wait for a response" action I have added the Adaptive card JSON code. 

Problem:
In the database, I have created columns for the "Option Sets (Choices)" as "BIT default 0" datatype. I am trying to store inside these columns the options results that the user has checked inside the form. Unfortunately, when I map the ID of the options sets inside the SQL server action it returns a string result which causes the flow to fail because the data type of the columns is a "BIT" and not "nvarchar". The bit data type is an integer that can take a value of 0, 1, or NULL.

What I want to achieve is the following:
I want to store the options checked by the user as a bit instead of a string inside the DB (0=false(unchecked), 1=true,(checked), null(nothing checked))

Please find below the JSON code of the Options sets:

           "type": "Input.ChoiceSet",
            "placeholder": "Placeholder text",
            "choices": [
                {
                    "title": "Test",
                    "value": "Test"
                },
                {
                    "title": "Office 365",
                    "value": "Office 365"
                },
                {
                    "title": "Azure Services",
                    "value": "Azure Services"
                },
                {
                    "title": "Cloud Solutions",
                    "value": "Cloud Solutions"
                }
            ],
            "style": "expanded",
            "id": "acLeadProductInterest",
            "isMultiSelect": true
        }
    ],


Please find below the flow result:

Capture.JPGCapture1.JPGCapture2.JPG
As you see in the screenshots I posted below, in the second photo the options results that I've checked are "Office365 and Azure", so in the SQL server action result from the Office 365 and Azure field are returning "false" where they should be "true" because they are selected. PS: I didn't map anything inside these fields.

What I have to modify for it works as expected?
Can someone please explain in detail and provide an example to achieve the following scenario?

Any help will be greatly appreciated.
Thank you.

1 ACCEPTED SOLUTION

Accepted Solutions

Three expressions, one per input:

 

if(contains(coalesce(variables('myChoiceOutput'),''),'Office 365'),true,false)

 

Similar approach for the other two

if(contains(coalesce(variables('myChoiceOutput'),''),'Azure Services'),true,false)

and

if(contains(coalesce(variables('myChoiceOutput'),''),'Cloud Solutions'),true,false)

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

12 REPLIES 12
abm
Super User III
Super User III

Hi @Julien2 

 

You mentioned the data type is int? So where you checking whether its 0, 1 0r null based on the values you getting?

 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials
efialttes
Super User III
Super User III

Hi!

"I want to store the options checked by the user as a bit instead of a string inside the DB (0=false(unchecked), 1=true,(checked), null(nothing checked))"

 

Do you mean ...

0=false(all 4 choice options unchecked),

1=true (at least one of the 4 choice options checked) ?

 

Thanx!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hi @abm ,

I am not checking whether if it's 0, 1 or null because the JSON result is returning a string not (True, False or 0,1). But in SQL Server action the services checked I mentioned should return true which means 1. Somehow, in DB it should store true for the checked values, false for the unchecked values. The issue is that it's returning false for all knowing that some options are checked.

Hello @efialttes ,

Exactly, if any value is checked so the result will be "True", else if nothing checked false.
Please have a look at this example:
Capture.JPG
Office 365, and Azure are checked so in the DB, it should store "True" for these values and false for cloud solutions.

Hi!

Then you need to transform your string into whatever format type is expected by your SQL server field. Integer? Boolean?

So let's assume choice output string is stored in a variable called 'myChoiceOutput'... just need to add a 'initialize variable' action block, name 'myChoiceOutput', type 'string, assgign as its value the adaptive card choice ouput from dynamic contents menu

Assuming SQL server field integer, I would suggest to assign the following expression

 

if(contains(coalesce(variables('myChoiceOutput'),''),','),1,0)

Assuming SQL server field boolean, I would use instead

if(contains(coalesce(variables('myChoiceOutput'),''),','),true,false)

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hello @efialttes ,

Yes, I want to convert the options results instead of a string to bool (true, or false) and of course, the options result (true or false) will be based on the checked and unchecked.

I have initialized a string variable and mapped into it the card choice output value.

Unfortunately, the SQL server action results return true for all the field where I have used the second expression you mentioned, knowing that while I am testing I have checked only "Office 365 and Azure" so both fields are true which is right but the others also are returning true result knowing that I haven't checked them.

Please have a look at this screenshot below:
Capture.JPGCapture1.JPG

The last field should return false because it's not mentioned in the string variable result.
Any idea why this happens?

Looking forward to your response.
Thanks.

Hi!

So firs problem solved, new problem arises... Then we are close to a happy ending, right?

give me some minutes to look into it

Thanx!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hi @efialttes ,
Yes, we are, take your time waiting for you!

Hi!

Can you share a screenshot from your 'SQL update row' action block design, so I can see which inputs you have and current data assigned?

You just shared a part of it, but not the design view

Thanx!



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



Hi @efialttes ,

Sure, please find below the SQL server action detail:
Capture.JPG
I have assigned for all the fields the second expression you mentioned.

Looking forward to your response.
Thanks

Three expressions, one per input:

 

if(contains(coalesce(variables('myChoiceOutput'),''),'Office 365'),true,false)

 

Similar approach for the other two

if(contains(coalesce(variables('myChoiceOutput'),''),'Azure Services'),true,false)

and

if(contains(coalesce(variables('myChoiceOutput'),''),'Cloud Solutions'),true,false)

Hope this helps



Each time you click on any of our inspiring answers 'Thumb up' icon...
...an ewok scapes from the stormtroopers.

Be grateful, Thumbs up! Save the Galaxy for free!


Escribo sobre Power Automate en:
https://medium.com/anyone-can-automate/

Proud to be a Flownaut!



View solution in original post

Hello @efialttes ,

Thank you very much for your support. Using the expressions you mentioned makes it works as expected.
I got a general question about the "Adaptive card on a teams channel and wait for response":

Do all the users in the current channel can respond to the form? Or only the form wait for only "ONE RESPOND".
For example, user1 has submitted the form in the morning, and another user which is user2 has signed later and wants to submit the form he will be able to do that? Or I have to run the flow again so he is able to submit again.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

V3_PVA CAmpaign Carousel.png

Community Challenge - Giveaways!

Participate in the Power Virtual Agents Community Challenge

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,925)