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 / Problem with if inside...
Power Apps
Unanswered

Problem with if inside a patch that is in a loop

(0) ShareShare
ReportReport
Posted on by

Hi,

 

I have this problem i have a form in canvas app in which i have several tabs, and for the 2nd and 3rd tab i display a common datacard attachments. In this common datacard attachments I added the following formula in the parameter OnAddFile. 

ClearCollect(
 AttachmentCollection,
 {
 AbsoluteUri: " ",
 DisplayName: " ",
 Id: " ",
 Name: " ",
 Value: " "
 }
);
ClearCollect(
 AttachmentCollectionCopy,
 {
 AbsoluteUri: " ",
 DisplayName: " ",
 Id: " ",
 Name: " ",
 Value: " "
 }
);
Collect(
 AttachmentCollection,
 DataCardValue117.Attachments
);
Collect(
 AttachmentCollectionCopy,
 AttachmentCollection
);
RemoveIf(
 AttachmentCollection,
 Id = " "
);
RemoveIf(
 AttachmentCollectionCopy,
 Id = " "
);

ForAll(
 AttachmentCollectionCopy,
 Patch(
 AttachmentCollection,
 ThisRecord,
 {
 Name: If( Not("Time" in ThisRecord.Name) And Not("Financials" in ThisRecord.Name), If(varTabSelected = 2, "Financials - " & ThisRecord.Name,"Time - " & ThisRecord.Name), If("Financials" in ThisRecord.Name, "Financials - " & ThisRecord.Name, "Time" in ThisRecord.Name ,"Time - " & ThisRecord.Name)) ,
 DisplayName: If( Not("Time" in ThisRecord.DisplayName) And Not("Financials" in ThisRecord.DisplayName), If(varTabSelected = 2, "Financials - " & ThisRecord.DisplayName,"Time - " & ThisRecord.DisplayName), If("Financials" in ThisRecord.DisplayName, "Financials - " & ThisRecord.DisplayName, "Time" in ThisRecord.DisplayName ,"Time - " & ThisRecord.DisplayName))
 }
 )
 );

 

I create myself a collection for attachments and then copy it in order to make a loop in which I will overwrite the names of added attachments.
When someone adds a new attachment, then depending on whether we are in the 2nd tab varTabSelected = 2, he wants to add the prefix "Financials", in the 3rd tab varTabSelected = 3 he adds the prefix "Time".

I also created a logic that checks if the user has already uploaded a file before, to which it overwrote, for example, the prefix "Financials" for such a case the name is to be left unchanged.

 

Unfortunately, this function does not work, and in the case when I add a file in the second tab it adds the prefix "Financials" to my file, but when I go to the third tab and add a file then already the new and previous file is overwritten with the prefix "Time".

 

Please give me some advice, do I have a bug in the logic somewhere or Patch can't handle such complex functions?

 

Best regards.

Categories:
I have the same question (0)

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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 529 Most Valuable Professional

#2
Haque Profile Picture

Haque 230

#3
Kalathiya Profile Picture

Kalathiya 217 Super User 2026 Season 1

Last 30 days Overall leaderboard