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 / Help with this code
Power Apps
Suggested Answer

Help with this code

(1) ShareShare
ReportReport
Posted on by 4
// 1. Buscar caminhão
Set(
    varCaminhao;
    LookUp(
        'Lista Caminhões';
        'Placa do Veículo' = TxtInputPlaca.Value
    )
);;
 
// 2. Buscar motorista
Set(
    varMotorista;
    LookUp(
        'Lista Motoristas';
        CNH = TxtInputDocs.Value
    )
);;
 
// 3. Verificar se não encontrou registro
If(
    IsBlank(varCaminhao) Or IsBlank(varMotorista);
    Notify(
        "Caminhão ou motorista não encontrado.";
        NotificationType.Error
    );
   
    // 4. Criar novo registro no Controle de Acesso
    Patch(
        'Lista Controle de Acesso';
        Defaults('Lista Controle de Acesso');
        {
            'Caminhão': { Id: varCaminhao.ID };
            'Motorista': { Id: varMotorista.ID };
            'Local de Carregamento Inicial': DrpLocais.Selected;
            'Status Inicial': { Value:"Entrada" };
            DataHoraEntrada: Now()
        }
    )
)


Invalid argument type. Expecting a Record value, but from a different schema.
Missing column. Your formula has a missing 'Value' column with a type of 'Text'.
error in patch code
Categories:
I have the same question (0)
  • Michael E. Gernaey Profile Picture
    53,479 Super User 2025 Season 2 on at
     
    It looks like you are trying to populate Choice columns? Also is this Dataverse or SharePoint?
     
    You have not provided any information about your Data, the Columns, the Types but based on the error you are providing a Record, but you are not providing the right record format.
     
    You do NOT need to provide a record to a Choice Column, if you have a drop down or combo box you simply have to provide what is .Selected as the value.
     
    The error however is telling you it expects { Value,  }
     
    Please also share a picture of the Errors so I can see what parts are the issue, along with each Column data type.
     

    If these suggestions help resolve your issue, Please consider Marking the answer as such and also maybe a like.

    Thank you!
    Sincerely, Michael Gernaey
  • WarrenBelz Profile Picture
    153,117 Most Valuable Professional on at
    Adding to what @Michael E. Gernaey has suggested, below is some code that avoids "one-time" global variables "clogging up" your resources, however assuming you are using SharePoint here, I will take a guess (and @Michael E. Gernaey is also correct here) that the issue lies in the highlighted line and that the DisplayFields of DrpLocais.Selected is not Value. If this is the case, you need to declare the actual field to get the output as below
    With(
       {
          _Caminhao;
          LookUp(
             'Lista Caminhões';
             'Placa do Veículo' = TxtInputPlaca.Value
          );
          _Motorista;
          LookUp(
             'Lista Motoristas';
             CNH = TxtInputDocs.Value
          )
       );
       If(
          IsBlank(_Caminhao) Or IsBlank(_Motorista);
          Notify(
             "Caminhão ou motorista não encontrado.";
             NotificationType.Error
          );
          Patch(
             'Lista Controle de Acesso';
             Defaults('Lista Controle de Acesso');
             {
                'Caminhão': {Id: _Caminhao.ID};
                'Motorista': {Id: _Motorista.ID};
                'Local de Carregamento Inicial': {Value: DrpLocais.Selected.FieldDisplayed};
                'Status Inicial': {Value: "Entrada"};
                DataHoraEntrada: Now()
             }
          )
       )
    )
     
  • Suggested answer
    CU13081548-1 Profile Picture
    8 on at
    The error you are facing indicates that the Patch function expects a record with a specific schema, and the field you are passing is not in the expected format, especially for Choice fields where a record with a Value column of text type is expected.
     
     
    // 1. Buscar caminhão
    Set(
    varCaminhao,
    LookUp(
    'Lista Caminhões',
    'Placa do Veículo' = TxtInputPlaca.Value
    )
    );

    // 2. Buscar motorista
    Set(
    varMotorista,
    LookUp(
    'Lista Motoristas',
    CNH = TxtInputDocs.Value
    )
    );

    // 3. Verificar se não encontrou registro
    If(
    IsBlank(varCaminhao) Or IsBlank(varMotorista),
    Notify(
    "Caminhão ou motorista não encontrado.",
    NotificationType.Error
    ),

    // 4. Criar novo registro no Controle de Acesso
    Patch(
    'Lista Controle de Acesso',
    Defaults('Lista Controle de Acesso'),
    {
    'Caminhão': { Id: varCaminhao.ID },
    'Motorista': { Id: varMotorista.ID },
    'Local de Carregamento Inicial': { Id: DrpLocais.Selected.ID }, // or {Value: DrpLocais.Selected.Value} if it is Choice
    'Status Inicial': { Value: "Entrada" },
    DataHoraEntrada: Now()
    }
    )
    )

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 765 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 272

Last 30 days Overall leaderboard