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

How to refresh/ reset the OnScan property code for each item in the gallery

Hi Team,

 

I am using a Scanner in my app. The code written in OnScan property runs and keeps it states while we are in the app.

 

However, I am looking for any way if the OnScan property state can be reset for each item in the gallery.

 

The thing happening here is when I select an item of gallery, the last state/ scanned value remains same.

 

Is there any way we can refresh the state of OnScan property and get the code rerun for each item of gallery?

 

Appreciate any help on this!!

1 ACCEPTED SOLUTION

Accepted Solutions
RandyHayes
Super User III
Super User III

@PurpleDeveloper 

One key point in my last reply : " (and I say that because IF this is in a Gallery, then the approach is different)"

 

So...as I gather your logic.  A user can enter a value in the weight and then press confirm.  You then want to "lock" the input to view mode, so there is no way to have the user enter anything else once they press confirm.

 

IF that is a complete and true statement, then the following will work:
(The below is predicated on your items in the Gallery having a unique ID.)

- For the Confirm Button OnSelect action:

    UpdateContext({lclConfirms: lclConfirms & ";" & Text(ThisItem.ID) & ";"})

- For the DisplayMode of the TextInput2

    If(";" & Text(ThisItem.ID) & ";" in lclConfirms, Disabled, Edit)

- For the DisplayMode of the Button: 

    TextInput2.DisplayMode

 

What the above does is just concatenate a text variable with the unique ID of the list item.  Then the other controls base their mode on the presence or lack of that ID in the text string.  The semicolons around all the ID values is just to make sure that the find of that ID in the text is exact.

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

View solution in original post

12 REPLIES 12
RandyHayes
Super User III
Super User III

@PurpleDeveloper 

The OnScan is an action of the control, not a property.  So you can utilize the Reset property of the Scanner control to reset the scanner in order for it to release its prior values.  

I could provide a few options on how to best do that, but I am not sure how you are designing your app and how the scanner control is set up in your app.  If you need more guidance on resetting the control, provide some details on your app design.

 

I hope this is helpful for you.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes
PurpleDeveloper
Helper III
Helper III

Hi @RandyHayes ,

 

Sure. My app screen looks like below :

PurpleDeveloper_0-1621022884572.png

and in my On Scan property, I am changing the Scanner text name from Scan T to Scan P. But what's happening currently here is when I select an item of gallery at first the Scanner name is 'Scan T' and as soon as I scan one barcode it changes to 'Scan P'. But in case if user doesn't scan the second barcode it still remains to 'Scan P' that's fine but when I go back and choose another item from the gallery it's on 'Scan P'. However, I need it to reset the scanner and should appear as 'Scan T' which comes up while starting the app.

 

Hope it make sense.

 

Let me know if you would like check on OnScan code as well, if that will make it more clear.

RandyHayes
Super User III
Super User III

@PurpleDeveloper 

A couple of things I am not following:
- Where is the Gallery in this picture?  How are you "choosing another item from the gallery"?

- What is the OnScan action formula that you have now where you have this logic for Scan T or P?

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

Hi @RandyHayes ,

 

Thanks for your quick turnaround. Ah I see there is only one item in this gallery as this is what I see in web browser. But there are list of items in the gallery.

And the formula for Scan T and Scan P is written in OnScan property of the scanner.

 

However, nevermind.. I got a workaround by adding the formula on back button of this gallery screen.

 

Set(gvscanname, "Scan T");

  and it appears to start the scanning fresh for each item in gallery.

RandyHayes
Super User III
Super User III

@PurpleDeveloper 

Yes, I was driving at the potential that you had some variable you were setting and clearing that out.  Sound like you have worked around the issue.

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes
PurpleDeveloper
Helper III
Helper III

Hi @RandyHayes ,

 

In addition to that, can I ask one more thing.. 

 

I am looking for disabling the text input after user confirms the weight.

 

PurpleDeveloper_0-1621026545141.png

If(Weight_ErrorMessage.Visible = false,TextInput2.DisplayMode = DisplayMode.View)

 

I have written above code in OnSelect property of 'Confirm Weight' but it  doesn't appear to be working.

 

Could you please suggest how can we achieve that?

 

Really appreciate all your help!! 

 

RandyHayes
Super User III
Super User III

@PurpleDeveloper 

You cannot set a control property in PowerApps much like you cannot set a cell in Excel to be a value from other cell.

You need to reference in PowerApps (again like Excel - as PowerApps was modeled around Excel).

 

So, your DisplayMode property of the TextInput2 control should be:

   If(Weight_ErrorMessage.Visible, Edit, View)

 

Now...this will also depend on the visibility of the label.  If you have set the Visible property to something like :

   IsBlank(Weight_ErrorMessage.Text)

Then this will create pain for your users because as soon as they type something into the textinput.  The label will go away and the text input will shift to view.

 

So in this case, you need to move your value-chain further a step, and into a snapshot variable.  

So, the formula on your button OnSelect action would need to take a snapshot of the value in the TextInput and then everything would be based on that (that's what I mean by moving the value-chain further).

So at its basics (and I say that because IF this is in a Gallery, then the approach is different), your formula on the OnSelect action would be:

    Set(weightValue, TextInput2.Text)

Then the Visible property of the label would be : IsBlank(weightValue)

The DisplayMode property of TextInput2 would be : If(IsBlank(weightValue), Edit, View)

 

This would give you that basic capability.

 

 

_____________________________________________________________________________________
Digging it? - Click on the Thumbs Up below. Solved your problem? - Click on Accept as Solution below. Others seeking the same answers will be happy you did.
Check out my PowerApps Videos too! And, follow me on Twitter @RandyHayes
PurpleDeveloper
Helper III
Helper III

Hi @RandyHayes ,

 

Thanks for the detailed information. It really helped.

 

However, when I m trying below on the confirm weight button in the Gallery, it changes the display mode for all TextInput to View whereas I just need for that particular item.

 

 

 Set(weightValue, TextInput2.Text)

Then the Visible property of the label would be : IsBlank(weightValue)

The DisplayMode property of TextInput2 would be : If(IsBlank(weightValue), Edit, View)

 

I tried referring it with ThisItem but can't figure out where to put.

RandyHayes
Super User III
Super User III

@PurpleDeveloper 

One key point in my last reply : " (and I say that because IF this is in a Gallery, then the approach is different)"

 

So...as I gather your logic.  A user can enter a value in the weight and then press confirm.  You then want to "lock" the input to view mode, so there is no way to have the user enter anything else once they press confirm.

 

IF that is a complete and true statement, then the following will work:
(The below is predicated on your items in the Gallery having a unique ID.)

- For the Confirm Button OnSelect action:

    UpdateContext({lclConfirms: lclConfirms & ";" & Text(ThisItem.ID) & ";"})

- For the DisplayMode of the TextInput2

    If(";" & Text(ThisItem.ID) & ";" in lclConfirms, Disabled, Edit)

- For the DisplayMode of the Button: 

    TextInput2.DisplayMode

 

What the above does is just concatenate a text variable with the unique ID of the list item.  Then the other controls base their mode on the presence or lack of that ID in the text string.  The semicolons around all the ID values is just to make sure that the find of that ID in the text is exact.

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

View solution in original post

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

secondImage

Demo Extravaganza is Back!

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

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Power Apps June 2021

June Power Apps Community Call

Don't miss the call this month on June 16th - 8a PDT

Top Solution Authors
Top Kudoed Authors
Users online (59,440)