cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
AnthonyRegnier
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
v-xida-msft
Community Support
Community Support

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

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
KrishnaV
Super User
Super User

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.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
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.
AnthonyRegnier
Helper V
Helper V

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

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.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
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.
AnthonyRegnier
Helper V
Helper V

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})

 

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.

Regards,
KrishnaV
Business Applications MVP, Microsoft Certified Trainer
Twitter | Linkedin | YouTube | GitHub
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.
v-xida-msft
Community Support
Community Support

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

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
UG GA Amplification 768x460.png

Launching new user group features

Learn how to create your own user groups today!

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

M365 768x460.jpg

Microsoft 365 Collaboration Conference | December 7–9, 2021

Join us, in-person, December 7–9 in Las Vegas, for the largest gathering of the Microsoft community in the world.

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