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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Added elements in a ga...
Power Apps
Unanswered

Added elements in a gallery doesn’t work

(0) ShareShare
ReportReport
Posted on by 64

Hello, good afternoon. I hope you are doing well.

 

I have a problem and I would like to know if you can help me.

 

I have a gallery where I inserted a text box to write the units of each product entered.

 

However, when I do the Patch, it takes the last selected number for all products.

 

For example, if the first product has 2 units purchased and the second product has 5 units purchased, during registration, both the first and second products are registered as if they had purchased 5 units each.

 

Here is the code:

 

ClearCollect(colSalMultiCod,{Códigos:ForAll(Split('Txt.Sal.MultiCod'.Text,Char(10)), {Result: ThisRecord.Value})});
ClearCollect(colSalMultiCod2,Ungroup(colSalMultiCod,"Códigos"));

ForAll(colSalMultiCod2,Patch(
Tabla_Salidas,
Defaults(Tabla_Salidas),
{
Código:colSalMultiCod2[@Result],
Cantidad:Value('Pdct.Cantidad'.Text)
}
));

IMG_5855.png

 

 

Thank you in advance. Best regards.

Categories:
  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    Hi @EduGaytan ,

    Is this what you are trying to do ?

    With(
     {
     wData:
     Split(
     'Txt.Sal.MultiCod'.Text,
     Char(10)
     )
     },
     Patch(
     Tabla_Salidas,
     ForAll(
     wData As aData,
     {
     Código: aData.Value,
     Cantidad: Value('Pdct.Cantidad'.Text)
     }
     )
     )
    )

     

    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.

    MVP (Business Applications)   Visit my blog Practical Power Apps

  • EduGaytan Profile Picture
    64 on at

    Thank you for your prompt response. I appreciate that the code you provided works flawlessly with a simple copy and paste.

     

    Regrettably, the issue still persists.

    However, I made an intriguing discovery.

    The number present in the last text box I click before pressing the Patch button ends up being the number that gets recorded in both registers in my database.

     

    I have been contemplating an alternative solution. Would it be feasible to include 'Pdct.Cantidad' in a collection and then, during the patch operation, return the result in a similar manner as colSalMulticod2?

     

    I look forward to your comments, thank you very much.

     

  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    Hi @EduGaytan ,

    I cannot see your data or your model, but my assumptions are that: -

    • You have a Text control or Label 'Txt.Sal.MultiCod' with some values separated by hard returns
    • You want each of these values creating new records in Tabla_Salidas with this value in the Código field
    • Also in the same record, you want a number from the content of 'Pdct.Cantidad' in the Cantidad field

    Is all of this correct ?

  • EduGaytan Profile Picture
    64 on at

    Thank you for your response, that's absolutely correct.

  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    @EduGaytan ,

    So just to be clearer, are you saying the new records all have the same value from Txt.Sal.MultiCod' (they will all be the same value from Pdct.Cantidad' as you only have one reference here - or is this a collection, in which case this is going to get complicated)

  • EduGaytan Profile Picture
    64 on at

    Thank you, I will trying to explain, all starts on a textbox called 'Txt.Sal.Código' (there is where the user going to put several product codes), in his property OnChange I have the next code:

     

    Collect(colTxtSal,'Txt.Sal.Código'.Text);
    Reset('Txt.Sal.Código');

    EduGaytan_0-1689379771210.png

    Then, 'Txt.SalMultiCod' is a textbox where is saved a lot of product codes, in this textbox I have the following code:

     

    Concat(colTxtSal, Value,Char(10))

     

    EduGaytan_2-1689379845475.png

     

    After, when I press the button "Ingresar", I create a new collection called ColSalMultiCod, where is the code:

    ClearCollect(colSalMultiCod,{Códigos:ForAll(Split('Txt.Sal.MultiCod'.Text,Char(10)), {Result: ThisRecord.Value})});
    ClearCollect(colSalMultiCod2,Ungroup(colSalMultiCod,"Códigos"));

    ForAll(colSalMultiCod2,Patch(
    Tabla_Salidas,
    Defaults(Tabla_Salidas),
    {
    Código:colSalMultiCod2[@Result],
    Cantidad:Value('Pdct.Cantidad'.Text)
    }
    ));

     

    I want to get each 'Pdct.Cantidad' value (rounded in yellow) for each product code in colSalMultiCod2 from the gallery:

     

    EduGaytan_3-1689380191077.png

     

    Thank you a lot, I look forward to your comments. 

  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    @EduGaytan ,

    How are the product codes in the text box related to 'Pdct.Cantidad'

  • EduGaytan Profile Picture
    64 on at

    Good point, I think they are related just in gallery but only in graphic way.

     

    How can I relate them?

  • WarrenBelz Profile Picture
    156,732 Most Valuable Professional on at

    @EduGaytan ,

    That is the whole point - unless they are in some way connected, how do you know which values to relate to each item in your text box ?

  • EduGaytan Profile Picture
    64 on at

    I thought it would work just by changing the value of the text box for each item, is there a possible solution?

     

    Maybe it's wrong from the start...

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Apps

#1
11manish Profile Picture

11manish 354 Super User 2026 Season 2

#2
M Bilal Khan Profile Picture

M Bilal Khan 330

#3
Mohsin Ali Profile Picture

Mohsin Ali 232

Last 30 days Overall leaderboard