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 / 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

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 759 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 310 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 228

Last 30 days Overall leaderboard