cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Helper V
Helper V

Patching Sharepoint value according to which gallery is used

Hello guys,

 

I have two galleries on top of each other that I just switch across using a button.

Each of these galleries have items I can click on and edit with forms.

 

One of the value I update uses a patch command but when I'm on the second gallery it does not work because in the code I'm using the first gallery to retrieive the right item to patch.

 

Would you be able to help me to enclose the code below with an IF statement according to which gallery I am?

 

Here is the code:

 

Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_AllProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
);
UpdateContext({Quantity: Blank()});
Reset(TxtIn_Qty);
UpdateContext({ShowUpdatedStock: true})

 

Thank you very much for your help! 

2 ACCEPTED SOLUTIONS

Accepted Solutions
Highlighted
Community Support
Community Support

Re: Patching Sharepoint value according to which gallery is used

Hi @AnthonyRegnier ,

Do the Gallery_RetiredProducts and Gallery_AllProducts connect to same SP List data source in your app?

 

I assume that the Gallery_RetiredProducts and Gallery_AllProducts connect to same SP List data source, based on the needs that you mentioned, I think a global variable could achieve your needs. Please consider take a try with the following workaround:

Add the following formula within the OnSelect property of the Gallery_RetiredProducts :

Set(CurrentGallery, "RetiredProducts")

Add the following formula within the OnSelect property of the Gallery_AllProducts:

Set(CurrentGallery, "AllProducts")

Note: Use the CurrentGallery variable to store which Gallery you are in now.

 

Then you need to modify your Patch formula as below:

Patch(
      'Stock Management',
      If(                               // Modify formula here
         CurrentGallery = "RetiredProducts",
         LookUp('Stock Management', Model= Gallery_RetiredProducts.Selected.Model),
         CurrentGallery = "AllProducts",
         LookUp('Stock Management', Model= Gallery_AllProducts.Selected.Model)
      ),
     {
        Stock: Value(Lbl_NewStockResult.Text)
     }
);
Set(CurrentGallery, Blank());   // Clear this CurrentGallery variable
UpdateContext({Quantity: Blank()});
Reset(TxtIn_Qty);
UpdateContext({ShowUpdatedStock: true})

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Helper V
Helper V

Re: Patching Sharepoint value according to which gallery is used

Hello!

 

Thank you!

I actually have already a variable in the OnSelect property of each Gallery (vRetired = True, and vRetired = False).

I believe the lookup formula wasnt working because it wasn't updating the product item number.

I got it working by keeping the current filter:

 

If(vRetired = false,
    Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_AllProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
));

If(vRetired = true,
    Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_RetiredProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
));

UpdateContext({Quantity: Blank()});
Reset(TxtIn_Qty);
UpdateContext({ShowUpdatedStock: true})

 

Thank you so much!

Anthony

View solution in original post

7 REPLIES 7
Highlighted
Super User
Super User

Re: Patching Sharepoint value according to which gallery is used

Hi @AnthonyRegnier ,

 

try this:
on Button select of destok and restock set the below formula:

UpdateContext({varUserStkType:"Restock"}) // on Select of the Restock button
UpdateContext({varUserStkType:"Destock"}) // on Select of the Destock button

OnSave click Icon:

if(varUserStkType="Restock",
Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_Restock.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
),
Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_Destock.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
))
UpdateContext({Quantity: Blank()});
Reset(TxtIn_Qty);
UpdateContext({ShowUpdatedStock: true})

 
I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Proud to be a Super User!

Regards,
KrishnaV
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
Highlighted
Helper V
Helper V

Re: Patching Sharepoint value according to which gallery is used

Hey mate! Thanks for the help.

 

Your piece of code is almost what I need :).

 

When I switch gallery I will update a context variable that I will use as a condition for the patch command to use the right gallery in the filter accordingly!

 

Thanks

Anthony

Highlighted
Super User
Super User

Re: Patching Sharepoint value according to which gallery is used

Hi @AnthonyRegnier ,

 

If that works for you would you mind marking it as a solution so that the new members of the community will make use of it.

 

I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Proud to be a Super User!

Regards,
KrishnaV
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
Highlighted
Helper V
Helper V

Re: Patching Sharepoint value according to which gallery is used

I have tried this but it's not working. On the "=" sign it says that it's an imcomatible type.

I thought I was just querying a string?

 

If(DataCardValue3.Text = 0, Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_RetiredProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
));

If(DataCardValue3.Text <> 0, Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_AllProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
));

UpdateContext({Quantity: Blank()});
Reset(TxtIn_Qty);
UpdateContext({ShowUpdatedStock: true})

 

Highlighted
Super User
Super User

Re: Patching Sharepoint value according to which gallery is used

Hi @AnthonyRegnier ,

 

Yes, they both are different data types, try this:

If(Value(DataCardValue3.Text) = 0, Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_RetiredProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
));

If(Value(DataCardValue3.Text) <> 0, Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_AllProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
));

UpdateContext({Quantity: Blank()});
Reset(TxtIn_Qty);
UpdateContext({ShowUpdatedStock: true})

Note: the change is I am converting the text to integer 😉


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Regards,
Krishna
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members find it more.


I hope this resolved your issue if you see any challenge/need further help please let me know I am always happy to do it for my community.

Proud to be a Super User!

Regards,
KrishnaV
If this post helps you give a 👍 and if it solved your issue consider Accept it as the solution to help the other members / new members of the community.
Highlighted
Community Support
Community Support

Re: Patching Sharepoint value according to which gallery is used

Hi @AnthonyRegnier ,

Do the Gallery_RetiredProducts and Gallery_AllProducts connect to same SP List data source in your app?

 

I assume that the Gallery_RetiredProducts and Gallery_AllProducts connect to same SP List data source, based on the needs that you mentioned, I think a global variable could achieve your needs. Please consider take a try with the following workaround:

Add the following formula within the OnSelect property of the Gallery_RetiredProducts :

Set(CurrentGallery, "RetiredProducts")

Add the following formula within the OnSelect property of the Gallery_AllProducts:

Set(CurrentGallery, "AllProducts")

Note: Use the CurrentGallery variable to store which Gallery you are in now.

 

Then you need to modify your Patch formula as below:

Patch(
      'Stock Management',
      If(                               // Modify formula here
         CurrentGallery = "RetiredProducts",
         LookUp('Stock Management', Model= Gallery_RetiredProducts.Selected.Model),
         CurrentGallery = "AllProducts",
         LookUp('Stock Management', Model= Gallery_AllProducts.Selected.Model)
      ),
     {
        Stock: Value(Lbl_NewStockResult.Text)
     }
);
Set(CurrentGallery, Blank());   // Clear this CurrentGallery variable
UpdateContext({Quantity: Blank()});
Reset(TxtIn_Qty);
UpdateContext({ShowUpdatedStock: true})

 

Please consider take a try with above solution, check if the issue is solved.

 

Best regards,

Community Support Team _ Kris Dai
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Highlighted
Helper V
Helper V

Re: Patching Sharepoint value according to which gallery is used

Hello!

 

Thank you!

I actually have already a variable in the OnSelect property of each Gallery (vRetired = True, and vRetired = False).

I believe the lookup formula wasnt working because it wasn't updating the product item number.

I got it working by keeping the current filter:

 

If(vRetired = false,
    Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_AllProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
));

If(vRetired = true,
    Patch(
   'Stock Management',
   First(Filter('Stock Management',Model=Gallery_RetiredProducts.Selected.Model)), 
   {Stock:Value(Lbl_NewStockResult.Text)}
));

UpdateContext({Quantity: Blank()});
Reset(TxtIn_Qty);
UpdateContext({ShowUpdatedStock: true})

 

Thank you so much!

Anthony

View solution in original post

Helpful resources

Announcements
secondImage

New Return to Workplace

Reopen responsibly, monitor intelligently, and protect continuously with solutions for a safer work environment.

Experience what’s next for Power Apps

Join us for an in-depth look at the new Power Apps features and capabilities at the free Microsoft Business Applications Launch Event.

Check this Out

Helpful information

Featuring samples like Return to the Workplace and Emergency Response Applications

secondImage

Power Platform 2020 release wave 2 plan

Features releasing from October 2020 through March 2021

Top Solution Authors
Top Kudoed Authors
Users online (3,604)