cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lefty
Impactful Individual
Impactful Individual

Help with If function

Hello everyone,

I have added an "Add picture" control to my form and I have a gallery displaying all the images being stored in a collection.

I have a text box, which I want the user to state the file name in, but as they have the option to add multiple images I want them to firstly be notified onscreen that the text box is empty, but also be notified if the text they have entered in the text box already exists in the collection - Some users with enter say test1 and upload multiple images under the same name, want to avoid this.

This is what I have so far on the OnChange property of my AddMediaButton1:

 

If(IsBlank('FileName-TxtInp'.Text), Notify("Enter a filename before proceeding", NotificationType.Error, 3000),

If(UploadedImage1.Image=SampleImage, "", Collect(ImageCollection, {Image:UploadedImage1.Image, FileName: 'FileName-TxtInp'.Text & "-" & DataCardValue39.Text //RefNumber field on the last screen
 & ".jpg"})))

 

 

Thanks

 

8 REPLIES 8
WarrenBelz
Super User
Super User

Hi @Lefty ,

Something like this should do it

If(
   IsBlank('FileName-TxtInp'.Text), 
   Notify("Enter a filename before proceeding", NotificationType.Error, 3000),
   If(
      !IsBlank(
         LookUp(
            ImageCollection,
            FileName='FileName-TxtInp'.Text
         ).FileName,
         Notify("Filename already exists", NotificationType.Error, 3000)
      ),	
      If(
         UploadedImage1.Image=SampleImage, "", 
         Collect(
            ImageCollection, 
            {
               Image:UploadedImage1.Image, 
               FileName: 'FileName-TxtInp'.Text & "-" & DataCardValue39.Text & ".jpg"
            }
         )
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Lefty
Impactful Individual
Impactful Individual

Hi @WarrenBelz 

 

Thanks for response, cant quiet see the where the error is, any help:

 

Lefty_0-1610702153045.png

 

Hi @Lefty ,

Free-typing - bracket in the wrong place

If(
   IsBlank('FileName-TxtInp'.Text), 
   Notify("Enter a filename before proceeding", NotificationType.Error, 3000),
   If(
      !IsBlank(
         LookUp(
            ImageCollection,
            FileName='FileName-TxtInp'.Text
         ).FileName
      ),
      Notify("Filename already exists", NotificationType.Error, 3000),	  
      If(
         UploadedImage1.Image=SampleImage, "", 
         Collect(
            ImageCollection, 
            {
               Image:UploadedImage1.Image, 
               FileName: 'FileName-TxtInp'.Text & "-" & DataCardValue39.Text & ".jpg"
            }
         )
      )
   )
)

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

 

 

Lefty
Impactful Individual
Impactful Individual

@WarrenBelz 

Thanks no code errors
BUT its not working the way I need,

It still allows me to add "Test" as the file name, in the text input field, and I can add multiple images, with the same name "Test" this is pretty much what I don't want it to do:

 

Lefty_0-1610705991416.png

 

Lefty
Impactful Individual
Impactful Individual

@WarrenBelz 

I thought of another way, just reset the textinput box after the image is added to the collection, making the user re-type, of course, they may type the same name but at least its more obvious the user has done so

@Lefty ,

I am a bit surprised that does not work as it would be a better solution than hoping the user does not type in "test" again. This code

If(
   !IsBlank(
      LookUp(
         ImageCollection,
         FileName='FileName-TxtInp'.Text
      ).FileName
   ),
   Notify("Filename already exists", NotificationType.Error, 3000),
    . . . . . . .	

is simply looking for a value in the FileName field of ImageCollection that is the same as the value the user typed in the 'FileName-TxtInp' Text box and giving a a warning (and stopping the save) if one is found.

What have I missed here?

 

Please click Accept as solution if my post helped you solve your issue. This will help others find it more readily. It also closes the item. If the content was useful in other ways, please consider giving it Thumbs Up.

Lefty
Impactful Individual
Impactful Individual

@WarrenBelz 

Is the issue because the collection is being created after?

Yes I agree it would be a better solution, but i'm unsure how to fix your suggestion, as that part of the code does not seem to check the collection for the name of the image, I have removed the refnumber field and only left the filename and .jpg to see if that was causing an issue, but allowed me to upload the same named files

@Lefty ,

Yes - if it was collected after the test, obviously that would not work.

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (2,359)