web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Patching as Default in...
Power Apps
Suggested Answer

Patching as Default into a OptionSetValue Dataverse Field

(1) ShareShare
ReportReport
Posted on by 42
Hello,
 
I am having trouble trying to patch new (default) values into a timetracking table called 'Timesheet'.  One of the fields in the table is a Choices type (or OptionSetValue) for Resource_Type with the options included of Contractor or Employee.  
 
In the form I have a patch statement that creates the timesheet, before rows of activities are added.  Below you can find the details.  I have tried different methods to get the value to patch, but it continues to throw an error that the type doesn't match the dropdown it is pulling from.
 
//Add Data from above collection into the Dataverse Timesheet Table
Patch(
            Timesheet,
            Defaults(Timesheet),
            {
                //included fields from the form
                Timesheet_WeekStartDate_ID: ddTSStartDate.Selected.crb01_dateid,
                Timesheet_StartDate: DateValue(ddTSStartDate.Selected.WeekStartDate),
                Resource_Name: ddEmployeeSelection.Selected.'Last Name, First Name',
                Resource_ID: ddEmployeeSelection.Selected.'Network ID',
                Resource_Email: ddEmployeeSelection.Selected.Email,
                Resource_ManagerName: ddEmployeeSelection.Selected.Manager,
                Timesheet_Approval_ApproverName: ddEmployeeSelection.Selected.Manager,
                Resource_CostCenter: ddEmployeeSelection.Selected.'Home Cost Center',
                Resource_Vendor: ddEmployeeSelection.Selected.Vendor,
                Resource_Role: ddEmployeeSelection.Selected.Role.Value,
                //custom fields with static values relating to timesheet processing
                Resource_Rate: 50.00,
                Resource_Type: ddEmployeeSelection.Selected.'Resource Type'
            }
        );
 
I have attempted the line using:
 
  • Resource_Type: ddEmployeeSelection.Selected.'Resource Type'
  • Resource_Type: {Value: ddEmployeeSelection.Selected.'Resource Type'}
The first one indicates that OptionSetValue is expected and type is text.  The second indicates OptionSetValue is expected and type is record.
 
 
Here is the field, from the Timesheet table, it needs to patch to, for reference.  I have external values for the options also set to Contractor and Employee respectively.
 
Categories:
I have the same question (0)
  • scalca Profile Picture
    243 Moderator on at
    can you pls share the items property of ddEmployeeSelection dropdown ? 
     
     
  • Suggested answer
    MichaelFP Profile Picture
    1,847 Super User 2025 Season 2 on at
    your ddEmployeeSelection is not a list of choice of the type 'Resource Type'. it is looking that are you set a custom collection of another type of record and after set the property resource type.
     
    Try the following
     
    Resource_type: Lookup(Choices('Name of optionset'), Value = ddEmployeeSelection.Selected.'Resource Type')
     
    or
     
    Resource_type: Lookup(Choices('Name of optionset'), Value = Value(ddEmployeeSelection.Selected.'Resource Type'))
  • PowerApp_Chaos Profile Picture
    42 on at
    @Scalca
     
    The employee dropdown pulls from one of two collections which are established when the user enters the timesheet page.  

    One of the collections (colAllEmployeesFormData) is an extraction of a timetracking employees table (which includes the field 'Resource Type'), this one would be used when the user is a manager or app admin, and needs access to create a timesheet for various employees.

    The other option (colUserFormData) is a collection extracted from the same dataset, but limited to only the current users info, enabling the timetracking employee to only see their name in the list.


    The patch statement OnSelect of a button labeled [Start Timesheet] gets the associated 'Resource_type' value from the name selected in these collections.


     
    If(varUserAdministrator=true||varUserManager=true,colAllEmployeesFormData,colUserFormData)




  • PowerApp_Chaos Profile Picture
    42 on at
    @MichaelFP, your solution (with a slight tweak in the exact scripting) worked!  
     
    I keep trying to mark your solution as the answer but it starts loading in the browser and never stops.  I have tried like 5 times now.  
     
    I essentially pulled the choices for the lookup from the database field, and then found the value within using the dropdown, as suggested.  Thank you so so so so much!  I cannot explain how long I spent researching this issue without results!!!
     
    Here is the final update to that part of the script which enabled it to recognize the loaded dropdown value as a choice.
     
    Patch(
                Timesheet,
                Defaults(Timesheet),
                {
                    //included fields from the form
                    Timesheet_WeekStartDate_ID: ddTSStartDate.Selected.crb01_dateid,
                    Timesheet_StartDate: DateValue(ddTSStartDate.Selected.WeekStartDate),
                    Resource_Name: ddEmployeeSelection.Selected.'Last Name, First Name',
                    Resource_ID: ddEmployeeSelection.Selected.'Network ID',
                    Resource_Email: ddEmployeeSelection.Selected.Email,
                    Resource_ManagerName: ddEmployeeSelection.Selected.Manager,
                    Timesheet_Approval_ApproverName: ddEmployeeSelection.Selected.Manager,
                    Resource_CostCenter: ddEmployeeSelection.Selected.'Home Cost Center',
                    Resource_Vendor: ddEmployeeSelection.Selected.Vendor,
                    Resource_Role: ddEmployeeSelection.Selected.Role.Value,
                    //custom fields with static values relating to timesheet processing
                    Resource_Rate: 50.00,
                    Resource_Type: LookUp(
                        Choices(Timesheet.Resource_Type),
                        Value in ddEmployeeSelection.Selected.'Resource Type',
                        Value
                    )
                }
            );
  • scalca Profile Picture
    243 Moderator on at
    you could pull the data directly into the dropdown with required record type
    Choices(TimeSheet.ResourceType)
    meaning that the patch function would work without to lookup
     
    in case the dropdown needs to be adjusted based on the user you can add an appropriate filter to the dropdown formula.
     
    that's just one more option

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 739 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 343 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard