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

19 REPLIES 19
RandyHayes
Super User
Super User

@Rivius 

ForAll is going to return a table...so, unless you are ForAll'ing on the sequence of records, I'm not sure how that would even fit in.  ??

_____________________________________________________________________________________
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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

The comma! Darn those commas!

RandyHayes
Super User
Super User

@Rivius 

Yes...I wish the forum had a formula editor in it...even to at least just validate syntax 😁

_____________________________________________________________________________________
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

Really want to show your appreciation? Buy Me A Cup Of Coffee!
Lefty
Post Prodigy
Post Prodigy

@RandyHayes @Rivius 

Thanks both for your help on this and it achieves the question I posted - having added the ability to delete the picture from the gallery, the code does not recognize a deleted value, i.e.
Picture1.jpg

Picture2.jpg
Picture3.jpg

 

I delete Picture2.jpg and I try to add another picture, it ends up putting Picture3.jpg again and the next picture if added without deleting any of the above, will correctly be Picture4.jpg
is there a way to fix this please, as firstly it duplicates the same name, but secondly does not use Picture2.jpg as missing in the sequence?
 

Rivius
Resolver III
Resolver III

You could do something like, If the countrows is greater than 0, Get the last record of the collection then count how many characters are in that last records file name.  Depending on how many characters are in total, get either 1 or more characters from the position the # would be in and add 1 to it.  For example if the filename is Picture8.jpg (12 characters) you'd do a Left() to get one character (the #8) then add 1 to it, but if the last filename is Picture22.jpg (13 characters) you'd want to get 2 characters (22) and add 1 to it. Etc.

 

This would ensure you didn't have any duplicates but would leave holes if you deleted somewhere in the middle.

1,2,3,4, delete #2, add 1 more = 1,3,4,5

RandyHayes
Super User
Super User

@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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

View solution in original post

@RandyHayes 

Thanks this works better than what it was, It cannot detect if picture1.jpg has been deleted and to use picture1.jpg as the name, but at least it detects the next available number rather than using the same number i.e. Picture1 is deleted Picture5 is used in its place.
I can make this above suggestion work, but I need to now somehow write the image name in another field, and that way I wont need to name the text fields "Picture 1 description" to "Picture 4 description" (I am not allowing more than 4 images or more than 4 descriptions)

RandyHayes
Super User
Super User

@Lefty 

Sounds good. 

I am not sure what your requirements are for putting the names in another field.  Are you looking for a comma separated list in a text column or something else?

_____________________________________________________________________________________
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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

@RandyHayes 

If its ok I will create a new question and reach out to you on that?

RandyHayes
Super User
Super User

@Lefty 

That will be perfect.

_____________________________________________________________________________________
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

Really want to show your appreciation? Buy Me A Cup Of Coffee!

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

secondImage

Power Apps Community Call

Please join us on Wednesday, October 20th, at 8a PDT. Come and learn from our amazing speakers!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (2,267)