cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
RiccoHipp1903
Resolver II
Resolver II

Unwanted Behavior with If and Update if On powerapps Collection

Hello guys,

 

I am struggeling hard with that. First I tell you what i wanted to achieve. This is My Shopping Cart Site 

RiccoHipp1903_0-1666081927123.png

You can choose an Employee and then Put it in a shopping card... you know

Now I had the Problem For every Item a new entry was made. 
Sometimes you have to correct something and add another one to the cart... so i though instead of making a new item, i wanted to update the Quantities. 
Therefore i had the blue button (test) with the following code 

 

If(
    CountIf(
        Licence_Shopping_Cart,
        Name = ThisItem.Title && MitarbeiterName = ComboBox_Search_Employee_Software_1.Selected.DisplayName
    ) > 0,
    UpdateIf(
        Licence_Shopping_Cart,
        (First(
            Filter(
                Licence_Shopping_Cart,
                Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email
            )
        ).Name = ThisItem.Title && First(
            Filter(
                Licence_Shopping_Cart,
                Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email
            )
        ).MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email),
        {
            Quantity: First(
                Filter(
                    Licence_Shopping_Cart,
                    Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email
                )
            ).Quantity + Int(TextInput2.Text)
        }
    ),
    Collect(
        Licence_Shopping_Cart,
        {
            Name: ThisItem.Title,
            Quantity: Int(TextInput2.Text),
            MitarbeiterName: ComboBox_Search_Employee_Software_1.Selected.DisplayName,
            MitarbeiterMail: ComboBox_Search_Employee_Software_1.Selected.Email
        }
    )
)

 

 

The Problem now is. Sometimes it works, sometimes it doesn't. I see no pattern.

 

What am I doing wrong?

Or have you any other ideas to achieve this simpler

1 ACCEPTED SOLUTION

Accepted Solutions
v-jefferni
Community Support
Community Support

Hi @RiccoHipp1903 ,

 

Your formula seems too complicated, please try below first and see if it could work:

If(
    CountIf(
        Licence_Shopping_Cart,
        Name = ThisItem.Title && MitarbeiterName = ComboBox_Search_Employee_Software_1.Selected.DisplayName
    ) > 0,
    UpdateContext({varQuantity:LookUp(Licence_Shopping_Cart,
        Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email,Quantity)+ Int(TextInput2.Text});
    Update(
        LookUp(
            Licence_Shopping_Cart,
            Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email
        ),
        {
            Quantity: varQuantity
        }
    ),
    Collect(
        Licence_Shopping_Cart,
        {
            Name: ThisItem.Title,
            Quantity: Int(TextInput2.Text),
            MitarbeiterName: ComboBox_Search_Employee_Software_1.Selected.DisplayName,
            MitarbeiterMail: ComboBox_Search_Employee_Software_1.Selected.Email
        }
    )
)

 

Best regards,

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

View solution in original post

2 REPLIES 2
v-jefferni
Community Support
Community Support

Hi @RiccoHipp1903 ,

 

Your formula seems too complicated, please try below first and see if it could work:

If(
    CountIf(
        Licence_Shopping_Cart,
        Name = ThisItem.Title && MitarbeiterName = ComboBox_Search_Employee_Software_1.Selected.DisplayName
    ) > 0,
    UpdateContext({varQuantity:LookUp(Licence_Shopping_Cart,
        Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email,Quantity)+ Int(TextInput2.Text});
    Update(
        LookUp(
            Licence_Shopping_Cart,
            Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email
        ),
        {
            Quantity: varQuantity
        }
    ),
    Collect(
        Licence_Shopping_Cart,
        {
            Name: ThisItem.Title,
            Quantity: Int(TextInput2.Text),
            MitarbeiterName: ComboBox_Search_Employee_Software_1.Selected.DisplayName,
            MitarbeiterMail: ComboBox_Search_Employee_Software_1.Selected.Email
        }
    )
)

 

Best regards,

Community Support Team _ Jeffer Ni

If this post helps, then please consider Accept it as the solution to help the other members find it.

hello @v-jefferni ,

thanks for the help. I tried it out. Had to Adjust a few things.  To make it without throwing an error

 /* Here */ UpdateContext({varQuantity: 1});
If(
    CountIf(
        Licence_Shopping_Cart,
        Name = ThisItem.Title && MitarbeiterName = ComboBox_Search_Employee_Software_1.Selected.DisplayName
    ) > 0,
    UpdateContext(
        {
            varQuantity: LookUp(
                Licence_Shopping_Cart,
                Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email,
                Quantity
            ) + Int(TextInput2.Text)
        }
    );
    Update(
        /*Here this*/ Licence_Shopping_Cart,
        LookUp(
            Licence_Shopping_Cart,
            Name = ThisItem.Title && MitarbeiterMail = ComboBox_Search_Employee_Software_1.Selected.Email
        ),
        {Quantity: varQuantity}
    ),
    Collect(
        Licence_Shopping_Cart,
        {
            Name: ThisItem.Title,
            Quantity: Int(TextInput2.Text),
            MitarbeiterName: ComboBox_Search_Employee_Software_1.Selected.DisplayName,
            MitarbeiterMail: ComboBox_Search_Employee_Software_1.Selected.Email
        }
    )
)

Now i have the problem, as soon as more than 2 Licence are in, a new item is generated for the next license ( And the name turns blank with the second Licence (fixable)

 

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,747)