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 Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

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.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (1,261)