cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SumanthDundi7
Helper III
Helper III

Avoid conflicts SharePoint PowerApps

Hi.. I have a SharePoint List_1 with a single line of text field called "TransactionCode" that has 1000+ unique items(promo codes).

I have another SharePoint List_2 where I have built a customised powerapp form with one simple field called "PromoCode" whose Default property is set to "First(SharePoint List_1).TransactionCode" so that user will be shown with only one promocode and submit the form. In the Submit button I have an idea to link with PowerAutomate to delete the transaction code from SharePoint List_1.

Now, when multiple users access or click New in the form at the same time. I would like to show unique codes to users. That means, if user1 and user2 access the form at the same time, codes that show up in the PromoCode field should be different for both the users. How can I achieve it? 

SumanthDundi7_0-1602694523359.png

 

1 ACCEPTED SOLUTION

Accepted Solutions

@SumanthDundi7 

Sure thing!  (and thanks for pointing this one out as I was getting pretty lost on that last post 😉 - this is pretty clear here).

 

So, as @timl outlines, you will need to do some sort of "record locking" (I assume this is what your "IsSelected" column is all about).

The key to this is going to be to refresh.  Simply setting the IsSelected to "Yes" in the list will not mean that others will see this reflected as "Yes" unless they refresh the data.

 

So, in your customized form, in the OnNew (or OnStart or OnVisible) action, you will need to do something similar to the following:

Refresh('SharePoint List_1');
Set(promoCode,
    First(Shuffle(Filter('SharePoint List_1', IsSelected="No")))
);
UpdateIf('SharePoint List_1', ID=promoCode.ID, {IsSelected:"Yes"})

This will set a Global Variable to the record in List 1 that is chosen by the shuffle function.

 

Set the Default on your PromoCode to promoCode.TransactionCode

 

Set the OnCancel of your SharePointIntegration to:

UpdateIf('SharePoint List_1', ID=promoCode.ID, {IsSelected:"No"})

 

Set the OnSuccess of your form to:

RemoveIf('SharePoint List_1', ID=promoCode.ID)

 

 

You would not need PowerAutomate for this either.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

10 REPLIES 10
timl
Super User III
Super User III

Hi @SumanthDundi7 

To retrieve a random promo code from list1, you can use the shuffle function like so:

First(Shuffle(SharePoint List_1)).TransactionCode

https://docs.microsoft.com/en-gb/powerapps/maker/canvas-apps/functions/function-shuffle

The caveat to this is that there is a random possibility that user1 and user2 could end up with the same promo code. To account for this possibility, you can check for uniqueness in the formula that you run in your Submit button.

Thank you @timl , But how can I avoid that random possibility of showing users with same promo codes when two users(or more) opened the form at the same time?

Hi @SumanthDundi7 

One way to avoid the random possibility of showing users the same promo code is to add a field to List_1. We can call this field PromocodeLocked and the purpose of this field is to indicate a promo code that we've already displayed to a user.

The high-level process to issue a promo code would be:

  • Retrieve a random promo code from List_1 where PromocodeLocked is false
  • Update List_1 and set PromocodeLocked to true for the promo code
  • If this succeeds, show the promo code to the user

We could also build some process to clear the PromocodeLocked field after a certain amount of time for codes that have not been redeemed.

Hi @timl, Thank you for your reply. Can you please help me with formulas for that what you  mentioned in bullet points?

@RandyHayes , Can you please ignore the other post which we were discussing and help me on this thread here? Hope you can go through this thread and help me on what exactly I was looking for.

@SumanthDundi7 

Sure thing!  (and thanks for pointing this one out as I was getting pretty lost on that last post 😉 - this is pretty clear here).

 

So, as @timl outlines, you will need to do some sort of "record locking" (I assume this is what your "IsSelected" column is all about).

The key to this is going to be to refresh.  Simply setting the IsSelected to "Yes" in the list will not mean that others will see this reflected as "Yes" unless they refresh the data.

 

So, in your customized form, in the OnNew (or OnStart or OnVisible) action, you will need to do something similar to the following:

Refresh('SharePoint List_1');
Set(promoCode,
    First(Shuffle(Filter('SharePoint List_1', IsSelected="No")))
);
UpdateIf('SharePoint List_1', ID=promoCode.ID, {IsSelected:"Yes"})

This will set a Global Variable to the record in List 1 that is chosen by the shuffle function.

 

Set the Default on your PromoCode to promoCode.TransactionCode

 

Set the OnCancel of your SharePointIntegration to:

UpdateIf('SharePoint List_1', ID=promoCode.ID, {IsSelected:"No"})

 

Set the OnSuccess of your form to:

RemoveIf('SharePoint List_1', ID=promoCode.ID)

 

 

You would not need PowerAutomate for this either.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

View solution in original post

@RandyHayes , Thank you very much for all your help in this. 

Here are my few other questions in this thing:

1. Can you please help me understand ID=promoCode.ID logic you have used. Is it like, we are searching for item ID whose TransactionCode equals that is set to variable called promoCode and set the IsSelected field to "Yes"?

2. Can you also let me know if is there any way I can hide the X icon as highlighted in the below image. OnCancel logic seems not working if I pressed this X icon instead "X Cancel" button.

SumanthDundi7_0-1603132895286.png

 

@SumanthDundi7 

So for number 1 - in the start we set a Variable to the *entire* record of the item from List_1.  That means it has, not only the transactionCode, but all of the columns of the item, including its unique ID.  With that we are able to reference it later in order to do other functions - like UpdateIf.

 

As for number 2 - not that I am aware of.  I would consider doing this as a standalone app rather than a customized form in SharePoint.  That way you would have complete control over the starting and closing.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up. Solved your problem? - Click on Accept as Solution. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too!

@RandyHayes , Randy, Thank you so much for your help! 

Helpful resources

Announcements
PA User Group

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group

MBAS Attendee Badge

Claim Your Badge & Digital Swag!

Check out how to claim yours today!

secondImage

Are Your Ready?

Test your skills now with the Cloud Skill Challenge.

secondImage

Demo Extravaganza is Back!

We are excited to announce that Demo Extravaganza for 2021 has started!

Top Solution Authors
Top Kudoed Authors
Users online (47,123)