cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lefty
Post Prodigy
Post Prodigy

Adding files to an attachment control

Hi,

I came across a great video by @RezaDorrani ((166) Power Apps Save Pictures to SharePoint - Camera Control Tutorial - YouTube) I'm wondering if we can change the code ever so slightly, which adds the files to the attachment control to increment the number by 1. I.e. vName would be by default Picture1, but if a user is adding more than 1 picture it would auto increment to Picture2, Picture3 etc. Reza was using GUID() to have unique file name, it would help if I can have an incremental number in its place here is the code:

 

Set(vName, "Picture1"); // anyway I can increment this by +1 if Picture1 already exists?
 Collect(
     colImages,
     {
         DisplayName: vName & ".jpg",
         Id: vName & ".jpg",
         Value: UploadedImage1.Image 


     }
 );

 Thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@Lefty 

Here is what you need in that scenario.

Collect(colImages,
    With({_name: "Picture" & Text(Max(ForAll(colImages, Value(Match(DisplayName, MultipleDigits).FullMatch)), Value) + 1)},
     {
         DisplayName: _name & ".jpg",
         Id: _name & ".jpg",
         Value: UploadedImage1.Image 
     }
    )
 );

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

View solution in original post

19 REPLIES 19
Rivius
Resolver III
Resolver III

Try a ForAll loop that runs CountRows each time on the collection and appends the number of rows +1 to the end of vName.  

DisplayName: vName & CountRows(colImages) + 1 & ".jpg"

RandyHayes
Super User III
Super User III

@Lefty 

Please consider changing your Formula to the following:

Collect(colImages,
    With({_name: "Picture" & Text(CountRows(colImages) + 1)}
     {
         DisplayName: _name & ".jpg",
         Id: _name & ".jpg",
         Value: UploadedImage1.Image 
     }
    )
 );

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@RandyHayes 's suggestion should work, I was thinking there would be more than 1 happening at the same time rather than incrementally one at a time.  I sometimes hold files in a collection before writing them to Dataverse in which case a ForAll situation would be helpful.

Lefty
Post Prodigy
Post Prodigy

@Rivius  Thanks will test more but It looks to do the trick nicely, just need to test it uploads which it should 😀

@RandyHayes  Thanks for your response, I've tried your suggestion and maybe I need to spend a bit of time looking at any typos, as is, it threw some errors:

Lefty_0-1620747485448.png

 

The collection needs to be initialized somewhere first to get Randy's code to work. You can do a ClearCollect(colImages,Blank()) somewhere else (but not in your collection code above or it'll erase it EACH time before beginning).

Lefty
Post Prodigy
Post Prodigy

@Rivius 

Thanks

But is there any reason why your suggested suggestion should not be used, it seems to work and I am able to attach the attachments and the number is incrementing +1 in the name of the file?

Rivius
Resolver III
Resolver III

If it works, roll with it!  Nothing wrong with using a ForAll, I really liked Randy's approach as well!

@Lefty 

Sorry, forgot a comma in the formula. Should be:

Collect(colImages,
    With({_name: "Picture" & Text(CountRows(colImages) + 1)},
     {
         DisplayName: _name & ".jpg",
         Id: _name & ".jpg",
         Value: UploadedImage1.Image 
     }
    )
 );
_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

@Rivius 

There is no need to "initialize" a collection.  PowerApps will apply the proper schema and record information without setting a blank to it...in fat, the setting a blank to a collection is not really a valid Formula in this case as it supplies no valid schema.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (59,792)