web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Power Apps - Building Power Apps
Answered

Create validation in the button

(0) ShareShare
ReportReport
Posted on by 198

Hello, I need some help validating the button to prevent it from creating the same links. I have the following screen:

 

Pizzolati_0-1711973778688.png

 


in it I can link / unlink machines / equipment. formula in the link button:

 

ForAll(
 ForAll(
 Filter(
 'GalleryTodasMaquinas/Equips'.AllItems;
 Checkbox2.Value=true
 );
 {
 'ID- Máquina':ThisRecord
 }
 );
 Patch(
 'Vínculos Funcionário/Máquina';
 Defaults('Vínculos Funcionário/Máquina');
 {
 'ID- Funcionario': GalleryTodosFuncionariosAtivos.Selected;
 'ID- Máquina': ThisRecord.'ID- Máquina'
 }
 )
)

 


However, I can create the same link infinitely many times. I would like to know if it is possible to create a validation between the two galleries so that I cannot create the same link more than once.

 

I tried using the following formula but without success the button always becomes inactive for some reason:

 

If(
 !IsBlank('GalleryTodasMaquinas/Equips'.Selected); // Verifica se há itens selecionados na primeira galeria
 If(
 !IsEmpty(
 Filter(
 GalleryTodosVinculadosMaq.AllItems; // Todas as máquinas vinculadas na segunda galeria
 'ID- Máquina' in ForAll(
 'GalleryTodasMaquinas/Equips'.AllItems; // Todas as máquinas selecionadas na primeira galeria
 'ID- Máquina' // Retorna uma lista de IDs das máquinas selecionadas na primeira galeria
 )
 )
 ); // Verifica se há alguma máquina na segunda galeria que está na lista de máquinas selecionadas na primeira galeria
 DisplayMode.Disabled; // Se houver uma correspondência; desabilita o botão
 DisplayMode.Edit // Se não houver correspondência; permite a edição do botão
 );
 DisplayMode.Disabled // Se não houver itens selecionados na primeira galeria; desabilita o botão
)
I have the same question (0)
  • Ramanachiappan Profile Picture
    179 Moderator on at
    Re: Create validation in the button

    Hi  @Pizzolati ,

    Try this one.
    Link button:
    ForAll(
    Filter(
    'GalleryTodasMaquinas/Equips'.AllItems,
    Checkbox2.Value=true
    ) As Record,
    Patch(
    'Vínculos Funcionário/Máquina';
    Defaults('Vínculos Funcionário/Máquina');
    {
    'ID- Funcionario': GalleryTodosFuncionariosAtivos.Selected;
    'ID- Máquina': Record.'ID- Máquina'
    }
    )
    )

    Button disable:
    If(
    !IsBlank('GalleryTodasMaquinas/Equips'.Selected);
    If(
    CountRows(
    Filter(
    GalleryTodosVinculadosMaq.AllItems;
    'ID- Máquina' in ForAll(
    'GalleryTodasMaquinas/Equips'.AllItems;
    'ID- Máquina'
    )
    )
    )=0,
    DisplayMode.Disabled,
    DisplayMode.Edit
    ),
    DisplayMode.Disabled
    )


    Best regards, 
    Ramanachiappan M

     

    If my response was helpful, please select "Accept as solution" to close the item. Your thumbs up would be highly appreciated if you found it useful. Thank you!

  • Pizzolati Profile Picture
    198 on at
    Re: Create validation in the button

    Hi Ramanachiappan, thanks for your reply. The formula to avoid creating identical links doesn't seem to have worked, I still manage to select a machine that already has a link and link it! Which is not the case.

     

    Pizzolati_0-1711975533265.png

     

  • Ramanachiappan Profile Picture
    179 Moderator on at
    Re: Create validation in the button

    Hi @Pizzolati ,

    Try this one 

    Button disable:
    If(
    !IsBlank('GalleryTodasMaquinas/Equips'.Selected);
    If(
    CountRows(
    Filter(
    GalleryTodosVinculadosMaq.AllItems;
    'ID- Máquina' in ForAll(
    'GalleryTodasMaquinas/Equips'.AllItems;
    'ID- Máquina'
    )
    )
    )>0,
    DisplayMode.Disabled,
    DisplayMode.Edit
    ),
    DisplayMode.Disabled
    )


    Best regards, 
    Ramanachiappan M

     

    If my response was helpful, please select "Accept as solution" to close the item. Your thumbs up would be highly appreciated if you found it useful. Thank you!

  • Pizzolati Profile Picture
    198 on at
    Re: Create validation in the button

    Hi Ramanachiappan, thanks for your reply. The formula to avoid creating equal links doesn't seem to have worked, the same error that I commented on in my post happened, now the button is always inactive.

     

    Pizzolati_0-1711976084586.png

     

    And also in the following formula that you gave me for Linking:

    ForAll(
    Filter(
    'GalleryTodasMaquinas/Equips'.AllItems,
    Checkbox2.Value=true
    ) As Record,
    Patch(
    'Vínculos Funcionário/Máquina';
    Defaults('Vínculos Funcionário/Máquina');
    {
    'ID- Funcionario': GalleryTodosFuncionariosAtivos.Selected;
    'ID- Máquina': Record.'ID- Máquina'
    }
    )
    )

    the following error occurs:

    the type of this argument 'cre14_IDMachine' does not match the expected type 'Record'. Type 'Error' found

  • Ramanachiappan Profile Picture
    179 Moderator on at
    Re: Create validation in the button

    Hi @Pizzolati ,

    If the previous code is functioning properly, it's advisable to stick with it. However, I need confirmation on whether the disable function code I was provided is also working correctly or not.

    Best regards, 
    Ramanachiappan M

     

    If my response was helpful, please select "Accept as solution" to close the item. Your thumbs up would be highly appreciated if you found it useful. Thank you!

  • Pizzolati Profile Picture
    198 on at
    Re: Create validation in the button

    Hello, so it's not working as I said the button now always stays inactive, even selecting a machine that is not linked!

  • Pizzolati Profile Picture
    198 on at
    Re: Create validation in the button

    Hi, I'm still having the same problem as before, even if I mark links other than the one that already exists the button still doesn't work

    Formula:

    If(
     !IsBlank('GalleryTodasMaquinas/Equips'.Selected);
     If(
     CountRows(
     Filter(
     GalleryTodosVinculadosMaq.AllItems;
     'ID- Máquina' in ForAll(
     'GalleryTodasMaquinas/Equips'.AllItems;
     'ID- Máquina'
     )
     )
     ) > 0;
     DisplayMode.Disabled;
     DisplayMode.Edit
     );
     DisplayMode.Disabled
    )

    Pizzolati_2-1711987779269.png

     

  • Pizzolati Profile Picture
    198 on at
    Re: Create validation in the button

    So I tried to do some validations by filtering my gallery by only those that have the CheckBox set to true, but to no success!

  • Verified answer
    Pizzolati Profile Picture
    198 on at
    Re: Create validation in the button

    I managed to do it using the following formula in my gallery filter:

    Filter(
     'Máquinas e Equipamentos';
     Ativo = true &&
     IsBlank(
     LookUp(
     GalleryTodosVinculadosMaq.AllItems;
     'ID- Máquina'.Descrição= Descrição
     )
     )
    )

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Chiara Carbone – Community Spotlight

We are honored to recognize Chiara Carbone as our Community Spotlight for November…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 624 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 384 Super User 2025 Season 2

#3
developerAJ Profile Picture

developerAJ 246

Last 30 days Overall leaderboard