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

How do I patch an optionset field

I have an entity, lets say Cars, with a field, Make, that is an option set. It is not an existing option set i.e. it is not a global option set.

 

The Make field optionset has these entries:

Honda

Toyota

Nissan

 

I want to add a record to the Cars entity but I can't get it to work. I've tried everything I could think of or find on the internet but no go. Some examples:

Patch(Cars, Default(Cars), {Make : "Honda"});

Patch(Cars, Default(Cars), {Make : Make.Honda});

 

I keep running into the error "The type of this argument 'Make' does not match the expected type 'OptionSetValue'. Found type 'Text'"

 

How do I patch an optionset value in an entity (especially if that optionset is not global)?

 

Thank you

 

Edit: I went back and tried the same with global option sets. That worked. So I'm guessing all the examples I tried were assuming global option sets.

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @abennear ,

Do you mean that the "Mark" field is a Local Option Set type column in your CDS Entity?

 

Based on the issue that you mentioned, I have made a test on my side (set up a "Local Option Set" column), and don't have the issue that you mentioned. The screenshot as below:

9.JPG

Patch(TaskLists, Defaults(TaskLists), {'Primary Name': "Local Option Set Submit", ProductRegion: 'ProductRegion (TaskLists)'.APAC})

 

Based on the formula that you mentioned, I think there is something wrong with it, please consider modify your formula as below:

Patch(
     Cars, 
     Default(Cars), 
    {
      Make : 'Make (Cars)'.Honda
    }
);

Please consider take a try with above formula, check if the issue is solved. Make sure you have referenced proper Option Set available value for the Make field in above Patch formula. The reference formula standard format as below:

'OptionSetName (EntityName)'.Option1
'OptionSetName (EntityName)'.Option2

....

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.

View solution in original post

2 REPLIES 2
v-xida-msft
Community Support
Community Support

Hi @abennear ,

Do you mean that the "Mark" field is a Local Option Set type column in your CDS Entity?

 

Based on the issue that you mentioned, I have made a test on my side (set up a "Local Option Set" column), and don't have the issue that you mentioned. The screenshot as below:

9.JPG

Patch(TaskLists, Defaults(TaskLists), {'Primary Name': "Local Option Set Submit", ProductRegion: 'ProductRegion (TaskLists)'.APAC})

 

Based on the formula that you mentioned, I think there is something wrong with it, please consider modify your formula as below:

Patch(
     Cars, 
     Default(Cars), 
    {
      Make : 'Make (Cars)'.Honda
    }
);

Please consider take a try with above formula, check if the issue is solved. Make sure you have referenced proper Option Set available value for the Make field in above Patch formula. The reference formula standard format as below:

'OptionSetName (EntityName)'.Option1
'OptionSetName (EntityName)'.Option2

....

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.

View solution in original post

That worked. Thanks a million.

 

For future reference, to display the options populate a drop down (for example) as follows

Choices('Make (Cars)')

 

And then to save the selected option:

Patch(Cars, Defaults(Cars), {'Make': Dropdown1.Selected.Value});

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (66,344)