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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Expecting Table on els...
Power Apps
Answered

Expecting Table on else_value of if statement?

(0) ShareShare
ReportReport
Posted on by

Hi guys,

 

im trying to do some validation on my app but something weird is happening and i dont know where is the error, if you can help me i would appreciate.

 

So, for context: its supposed to check the state in parameter, then check which items are checked on the gallery, go through them all and send a notification to the next user, if the message is sent then i will patch a sharepoint list with the next state ('Estado') and add the user to the AlreadySent collection.

 

//Everything fine until here:

Set(ResponsavelDecisaoCompras,First(Filter(ListaDecisoes,Title="Decisão Compras")).Responsavel.Email);
If(Param("state")="VRA",ForAll(ViewPropostasGallery.AllItems,If(PropostaCheck.Value,If(Or(IsEmpty(AlreadySent),CountIf(AlreadySent,User=ResponsavelDecisaoCompras)=0),If(NotifyAdmissao.Run(ResponsavelDecisaoCompras,JSON(ViewPropostasGallery.AllItems,JSONFormat.IgnoreBinaryData&JSONFormat.IgnoreUnsupportedTypes),"https://web.powerapps.com/apps/7be6c3f4-e230-45a8-ba7c-9c181383cc80?validation="&true&"&department="&Departamento&"&state=DC").response,Patch('Proposta Admissão/Alteração de Artigo em Armazém',{ID:ThisRecord.ID},{Estado:{Value:"Decisão Compras"}});Collect(AlreadySent,{User:ResponsavelDecisaoCompras}))))));

 

// but when i add the patch to the item in case of the user already got a notification i will get the error 'Invalid argument type (Record). Expecting a Table value instead':

Set(ResponsavelDecisaoCompras,First(Filter(ListaDecisoes,Title="Decisão Compras")).Responsavel.Email);
If(Param("state")="VRA",ForAll(ViewPropostasGallery.AllItems,If(PropostaCheck.Value,If(Or(IsEmpty(AlreadySent),CountIf(AlreadySent,User=ResponsavelDecisaoCompras)=0),If(NotifyAdmissao.Run(ResponsavelDecisaoCompras,JSON(ViewPropostasGallery.AllItems,JSONFormat.IgnoreBinaryData&JSONFormat.IgnoreUnsupportedTypes),"https://web.powerapps.com/apps/7be6c3f4-e230-45a8-ba7c-9c181383cc80?validation="&true&"&department="&Departamento&"&state=DC").response,Patch('Proposta Admissão/Alteração de Artigo em Armazém',{ID:ThisRecord.ID},{Estado:{Value:"Decisão Compras"}});Collect(AlreadySent,{User:ResponsavelDecisaoCompras})),Patch('Proposta Admissão/Alteração de Artigo em Armazém',{ID:ThisRecord.ID},{Estado:{Value:"Decisão Compras"}})))));

 

what im doing wrong?

Categories:
  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @User7 

    The problem stems from how you are viewing Formulas in PowerApps.  That formula is very "code-like" and PowerApps is not a coding platform.  Why I say this is...Formulas in PowerApps evaluate and return something...maybe nothing, maybe something, BUT, if they return something (as is the case of your Flow and the Patch function) the return types must match.  In your scenario, adding the Patch changes the return type of the If statement.  

    Also, your use of ForAll is that of a development For/Loop...ForAll is a function that returns a table or records.

    So, bottom line, you are mismatching the types of the returns within the ForAll.  Since ForAll is trying to create a record for each iteration of the ForAll, it is finding mismatch types.

     

    You might consider this Formula as an alternative:

    If(Param("state")="VRA",
     With({_sent:
     ForAll(Filter(ViewPropostasGallery.AllItems, PropostaCheck.Value && !(ResponsavelDecisaoCompras in AlreadySent.User)) As _item,
     {sent: NotifyAdmissao.Run(ResponsavelDecisaoCompras, 
     JSON(ViewPropostasGallery.AllItems, JSONFormat.IgnoreBinaryData & JSONFormat.IgnoreUnsupportedTypes),
     "https://web.powerapps.com/apps/7be6c3f4-e230-45a8-ba7c-9c181383cc80?validation="&true&"&department="... Admissão/Alteração de Artigo em Armazém',
     {ID: _item.ID},
     {Estado:{Value:"Decisão Compras"}}
     ),
     ID: _item.ID,
     User: ResponsavelDecisaoCompras
     }
     )},
     
     Patch('Proposta Admissão/Alteração de Artigo em Armazém',
     ForAll(Filter(_sent, !sent),
     {ID: ID,
     Estado:{Value:"Decisão Compras"}
     }
     )
     );
     
     Collect(AlreadySent,
     ForAll(Filter(_sent, sent),
     {User: User}
     )
     );
     )
    ); 
    

    In this formula we first start out doing the ForAll on the records from the Gallery that are checked and the ResponsavelDecisaoCompras is not in your collection AlreadySent.  

    I *assume* your flow is returning a true or false value - But, I am skeptical because typically it would be a property of your return.  Your flow does not have anything at the end to indicate this line -  yourflow.Run(....).ReturnValue

    So, that might need some resolution.

     

    Anyway, the first ForAll creates a Table of records that will contain the true or false return of the flow, the ID of the item from the Gallery, and the User from the Gallery record.  This is stored in a Scoped variable called _sent

     

    Next we iterate through the _sent table or records where NOT sent.  This creates (with the ForAll) a table of records with the ID and Estado value.  This table is then passed to the Patch statement and Patch will then change all the records in your datasource based on the ID.

     

    Then, because you have this collection, we then add any records that were sent to it.  Again, we use a ForAll to create a table of records with the User column for all the records in the _sent table that were sent.

     

    I am not entirely clear on all the moving parts you have with the flow, so again, I am skeptical on that one.  Also, I typed this by hand, so there might be some missing separators or syntax issues...but I believe it is pretty complete.

     

    I hope this is helpful for you.

     

  • HS-02011419-0 Profile Picture
    on at

    Hi Randy, 

     

    thanks for the clarification of the types, it was very helpfull to understand how does ForAll works and so.. My workaround was simpler ^^ i just return a empty Table() after the notify() this was where the error persisted.. So final code: 

    Set(ResponsavelDecisaoCompras,First(Filter(ListaDecisoes,Title="Decisão Compras")).Responsavel.Email);
    //Estado Validação Responsável Área
    If(Param("state")="VRA",ForAll(ViewPropostasGallery.AllItems,If(PropostaCheck.Value,If(IsEmpty(AlreadySent) || CountIf(AlreadySent,User=ResponsavelDecisaoCompras)=0,If(NotifyAdmissao.Run(ResponsavelDecisaoCompras,JSON(ThisRecord,JSONFormat.IgnoreBinaryData&JSONFormat.IgnoreUnsupportedTypes),"https://web.powerapps.com/apps/7be6c3f4-e230-45a8-ba7c-9c181383cc80?validation="&true&"&department="&Departamento&"&state=DC").response,Patch('Proposta Admissão/Alteração de Artigo em Armazém',{ID:ThisRecord.ID},{Estado:{Value:"Decisão Compras"}});Collect(AlreadySent,{User:ResponsavelDecisaoCompras}),Notify("Ocorreu um erro no envio da notificação da proposta "&ID,NotificationType.Error,3000);Table({})),Patch('Proposta Admissão/Alteração de Artigo em Armazém',{ID:ThisRecord.ID},{Estado:{Value:"Decisão Compras"}})))));

    and yes, my flow call was returning a response (the link was shortened).

     

    Thanks for the help 😉

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 342 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 271

#3
Mohsin Ali Profile Picture

Mohsin Ali 239

Last 30 days Overall leaderboard