cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
niteshdambale
Level: Powered On

How to set text variable value to an Optionset in PowerApp

Dear All,

 

On an App i've used an OptionSet field which lists desired values during app execution. Further I have also used a AI Builder FormProcessor which reads a PDF document and provides me text values. I have stored the values retrieved in a variable. (Using UpdateContext function on the Onchange property of Formprocessor.)

 

Now i wish to set the retrieved value (avaialble in variable) to the optionset field. Any help would be great.

 

Regards,

 

 

 

 

2 REPLIES 2
Community Support Team
Community Support Team

Re: How to set text variable value to an Optionset in PowerApp

Hi @niteshdambale ,

Could you please share a bit more about your scenario?

Do you want to set a text value back to a OptionSet type field in your CDS Entity from your app?

 

If you want to set a text value back to a OptionSet type field in your CDS Entity from your app, I afraid that there is no way to achieve your needs in PowerApps currently.

The 'Option Set' field in CDS Entity is required to provide Option Set type value only, you could not assign a Text value back to Option Set field.

 

As an alternative solution, I think the If function could achieve your needs. You could consider patch corresponding Option Set option value back to the Option Set field based on the Text variable value.

I assume that you want to use Patch function to patch data back to the Option Set field, please take a try with the following formula:

Patch(
          'CDSEntity',
          Defaults('CDSEntity'),
          {
            ...,
            OptionSetColumn: If(
                                                   TextVariable = "value1",        /* <-- TextVariable represents the text variable that you set using UpdateContext function */
                                                   OptionSetName.Option1,         /* <-- OptionSetName represents the name of your Option Set type, which binds to your OptionSetColumn*/
                                                   TextVariable = "value2",
                                                   OptionSetName.Option2,
                                                   TextVariable = "value3",
                                                   OptionSetName.Option3,
                                                   ...
                                            )
          }
)

If you use Edit form to submit your data, please set the Update property of the Option Set field data card in your Edit form to following:

If(
            TextVariable = "value1",        /* <-- TextVariable represents the text variable that you set using UpdateContext function */
            OptionSetName.Option1,         /* <-- OptionSetName represents the name of your Option Set type, which binds to your OptionSetColumn*/
            TextVariable = "value2",
            OptionSetName.Option2,
            TextVariable = "value3",
            OptionSetName.Option3,
            ...
)

Please consider take a try with above alternative solution, then check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Highlighted
niteshdambale
Level: Powered On

Re: How to set text variable value to an Optionset in PowerApp

Hi @v-xida-msft,

 

Thanks for your reply.

 

Here's bit more information as requested :

 

1) Using Patch Function I am able to patch the CDS entity --> Optionset fields sucessfully. The sample function is pasted below for your reference

 

Capture.PNG

 

 

 

 

 

 

 

 

 

(1) Here "Title" & "Gender" are Optionset fields in CDS entity

(2) Nationality is a Lookup field in CDS entity.

(3) Filter "First"is used to search and drill down to exact record which is to be updated

 

Now the query is as follows :

 

I have a powerapp which uses form processor to read PDF document. On change event of the form processor i have captured all values in variables. Example :

 

Capture.PNG

 

Here title, gender & nationality are my varaibles. I am sucessfully able to store the value of form processor fields into variables.

Now on the power app formscreen i have placed three fields mentioned above.

 

Capture.PNG

 

My query is, i wish to set the Values present in variables to the Optionset and Lookup fields on the form. E.g. Variable Gender Provides me text "Female". I have an optionset name "Female" with value 10000001.

 

Is this possible ?

 

Hello @HSheild your help would be appreciated..

 

 

Regards,

 

Nitesh

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

sixthImage

Power Platform World Tour

Find out where you can attend!

Power Platform 2019 release wave 2 plan

Power Platform 2019 release wave 2 plan

Features releasing from October 2019 through March 2020

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

Top Kudoed Authors (Last 30 Days)
Users online (5,540)