Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Power Apps Pro Dev & ISV
Suggested answer

Power apps code error

(2) ShareShare
ReportReport
Posted on by 10
// Update CRM Leads table
Patch(
    'CRM Leads',
    SelectedLead,
    {
        'Funnel Stage': DropdownFunnelStage.Selected,
        Status: DropdownStatus.Selected,
        'Last Activity Date': Now(),
        'Reason for Loss': If(ShowLostFields, DropdownLostReason.Selected, Blank()),
        'Loss Date': If(ShowLostFields, DatePickerLost.SelectedDate, Blank()),
        'Waiting List Reason': If(ShowWaitingFields, DropdownWaitingReason.Selected, Blank()),
        'Waiting List Date': If(ShowWaitingFields, DatePickerWaiting.SelectedDate, Blank())
    }
);
// Create CRM Leads Activities record
If(
    !IsBlank(DropdownFunnelStage.Selected),
    Patch(
        'CRM Leads Activities',
        Defaults('CRM Leads Activities'),
        {
            Lead: SelectedLead,
            'Activity Type': DropdownFunnelStage.Selected,
            'Sub-Stage':
                If(
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.'Follow Up',
                    LookUp(Choices('CRM Leads Activities'.'Sub-Stage'), Value = DropdownFollowUp.Selected.Value),
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Tour,
                    LookUp(Choices('CRM Leads Activities'.'Sub-Stage'), Value = DropdownTour.Selected.Value),
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Assessment,
                    LookUp(Choices('CRM Leads Activities'.'Sub-Stage'), Value = DropdownAssessment.Selected.Value),
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Admission,
                    LookUp(Choices('CRM Leads Activities'.'Sub-Stage'), Value = DropdownAdmission.Selected.Value)
                ),
            'Activity Date':
                If(
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.'Follow Up', DatePickerFollowUp.SelectedDate,
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Tour, DatePickerTour.SelectedDate,
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Assessment, DatePickerAssessment.SelectedDate,
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Admission, DatePickerAdmission.SelectedDate
                ),
            Notes:
                If(
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.'Follow Up', TextNotesFollowUp.Text,
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Tour, TextNotesTour.Text,
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Assessment, TextNotesAssessment.Text,
                    DropdownFunnelStage.Selected = 'Funnel Stage (CRM Leads)'.Admission, TextNotesAdmission.Text
                )
        }
    )
);
// Refresh gallery and reset form
Set(SelectedLead, LookUp('CRM Leads', LeadID = SelectedLead.LeadID));
Set(ShowLostFields, false);
Set(ShowWaitingFields, false);
Notify("Lead updated successfully", NotificationType.Success)



 
The expression was intended to perform the following actions when the 'ButtonSubmit' control is selected:
1. **Patch the 'CRM Leads' Table**: It updates the selected lead record with various fields such as Funnel Stage, Status, Last Activity Date, Reason for Loss, Loss Date, Waiting List Reason, and Waiting List Date. The values for these fields are derived from dropdowns, date pickers, and conditional logic based on the visibility of certain fields.
2. **Patch the 'CRM Leads Activities' Table**: If the selected Funnel Stage is not blank, it attempts to create a new record in the 'CRM Leads Activities' table with fields like Lead, Activity Type, Sub-Stage, Activity Date, and Notes. The values for these fields are also derived from dropdowns, date pickers, and conditional logic.
3. **Update Global Variables**: It sets the `SelectedLead` variable to the updated lead record, and it also sets the `ShowLostFields` and `ShowWaitingFields` variables to false.
4. **Notify the User**: It sends a notification to the user indicating success.
### Errors Summary:
1. **Invalid Arguments for Patch**: The `Patch` function is receiving arguments that do not match the expected types. Specifically, it expects an `OptionSetValue` for the 'Funnel Stage' but is receiving a `Record`.
2. **Incompatible Types for Comparison**: There are multiple instances where comparisons are being made between incompatible types, such as comparing `Record` types with `OptionSetValue`.
3. **Invalid Column Names**: The expression references a column named 'Lead', which does not exist in the 'CRM Leads Activities' table; the closest match is 'LeadID'.
4. **Unrecognized Names**: The expression includes references to 'Text' that are not recognized, leading to critical errors.
5. **Invalid Arguments in If Function**: There are issues with the arguments being passed to the `If` function, indicating that the conditions or values provided are not valid.
Overall, the expression has several critical and severe errors that need to be addressed to ensure it functions as intended.
  • Suggested answer
    mmbr1606 Profile Picture
    13,193 Super User 2025 Season 1 on at
    Power apps code error
    hey
     
     
    did you have the chance of trying what i suggested?
     

    If my answer was helpful and solved your issue, please mark it as the verified answer.

    If it helped but didn’t fully solve it, I’d appreciate a like. 😊

    And if you’d like to support me, feel free to buy me a coffee.

  • Suggested answer
    mmbr1606 Profile Picture
    13,193 Super User 2025 Season 1 on at
    Power apps code error
    hey
     
     
    thanks for clarifying, maybe this helps:
     
    Patch(
        'CRM Leads',
        SelectedLead,
        {
            'Funnel Stage': DropdownFunnelStage.Selected,
            Status: DropdownStatus.Selected,
            'Last Activity Date': Now(),
            'Reason for Loss': If(ShowLostFields, DropdownLostReason.Selected, Blank()),
            'Loss Date': If(ShowLostFields, DatePickerLost.SelectedDate, Blank()),
            'Waiting List Reason': If(ShowWaitingFields, DropdownWaitingReason.Selected, Blank()),
            'Waiting List Date': If(ShowWaitingFields, DatePickerWaiting.SelectedDate, Blank())
        }
    );
    
    If(
        !IsBlank(DropdownFunnelStage.Selected),
        Patch(
            'CRM Leads Activities',
            Defaults('CRM Leads Activities'),
            {
                LeadID: SelectedLead,
                'Activity Type': DropdownFunnelStage.Selected,
                'Sub-Stage': Switch(
                    DropdownFunnelStage.Selected.Value,
                    "Follow Up", DropdownFollowUp.Selected,
                    "Tour", DropdownTour.Selected,
                    "Assessment", DropdownAssessment.Selected,
                    "Admission", DropdownAdmission.Selected,
                    Blank()
                ),
                'Activity Date': Switch(
                    DropdownFunnelStage.Selected.Value,
                    "Follow Up", DatePickerFollowUp.SelectedDate,
                    "Tour", DatePickerTour.SelectedDate,
                    "Assessment", DatePickerAssessment.SelectedDate,
                    "Admission", DatePickerAdmission.SelectedDate,
                    Blank()
                ),
                Notes: Switch(
                    DropdownFunnelStage.Selected.Value,
                    "Follow Up", TextNotesFollowUp.Text,
                    "Tour", TextNotesTour.Text,
                    "Assessment", TextNotesAssessment.Text,
                    "Admission", TextNotesAdmission.Text,
                    Blank()
                )
            }
        )
    );
    
    Set(SelectedLead, LookUp('CRM Leads', LeadID = SelectedLead.LeadID));
    Set(ShowLostFields, false);
    Set(ShowWaitingFields, false);
    Notify("Lead updated successfully", NotificationType.Success)
    
    If my answer was helpful and it solved your issue please mark it as verified answer. If it helped but did not solve please consider giving me a like :)
  • KM-29011521-0 Profile Picture
    10 on at
    Power apps code error


    I keep getting this, even when using your provided code - I'm using choice columns in my dataverse tables. 

    Invalid argument type. Expecting a OptionSetValue (Funnel Stage (CRM Leads)) value, but of a different schema.
  • mmbr1606 Profile Picture
    13,193 Super User 2025 Season 1 on at
    Power apps code error
    hey
     
     
    can u try this approach:
     
    // Update CRM Leads table
    Patch(
        'CRM Leads',
        SelectedLead,
        {
            'Funnel Stage': DropdownFunnelStage.Selected.Value,
            Status: DropdownStatus.Selected.Value,
            'Last Activity Date': Now(),
            'Reason for Loss': If(ShowLostFields, DropdownLostReason.Selected.Value, Blank()),
            'Loss Date': If(ShowLostFields, DatePickerLost.SelectedDate, Blank()),
            'Waiting List Reason': If(ShowWaitingFields, DropdownWaitingReason.Selected.Value, Blank()),
            'Waiting List Date': If(ShowWaitingFields, DatePickerWaiting.SelectedDate, Blank())
        }
    );
    
    // Create CRM Leads Activities record
    If(
        !IsBlank(DropdownFunnelStage.Selected.Value),
        Patch(
            'CRM Leads Activities',
            Defaults('CRM Leads Activities'),
            {
                LeadID: SelectedLead,
                'Activity Type': DropdownFunnelStage.Selected.Value,
                'Sub-Stage': Switch(
                    DropdownFunnelStage.Selected.Value,
                    "Follow Up", DropdownFollowUp.Selected,
                    "Tour", DropdownTour.Selected,
                    "Assessment", DropdownAssessment.Selected,
                    "Admission", DropdownAdmission.Selected,
                    Blank()
                ),
                'Activity Date': Switch(
                    DropdownFunnelStage.Selected.Value,
                    "Follow Up", DatePickerFollowUp.SelectedDate,
                    "Tour", DatePickerTour.SelectedDate,
                    "Assessment", DatePickerAssessment.SelectedDate,
                    "Admission", DatePickerAdmission.SelectedDate,
                    Blank()
                ),
                Notes: Switch(
                    DropdownFunnelStage.Selected.Value,
                    "Follow Up", TextNotesFollowUp.Text,
                    "Tour", TextNotesTour.Text,
                    "Assessment", TextNotesAssessment.Text,
                    "Admission", TextNotesAdmission.Text,
                    Blank()
                )
            }
        )
    );
    
    // Refresh gallery and reset form
    Set(SelectedLead, LookUp('CRM Leads', LeadID = SelectedLead.LeadID));
    Set(ShowLostFields, false);
    Set(ShowWaitingFields, false);
    Notify("Lead updated successfully", NotificationType.Success)
    
     
     
    If my answer was helpful and it solved your issue please mark it as verified answer. If it helped but did not solve please consider giving me a like :)

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

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Announcing the Engage with the Community forum!

This forum is your space to connect, share, and grow!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 791 Most Valuable Professional

#2
MS.Ragavendar Profile Picture

MS.Ragavendar 410

#3
mmbr1606 Profile Picture

mmbr1606 275 Super User 2025 Season 1