@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.