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

'unique' reference number is duplicating error

I'm really struggling with this error which is essentially making my app unusable so I wonder if anyone here might have a suggestion. I'll try to be as clear as I can, I have also spoken about this before on this thread which helped me find half a solution.

 

My app is supposed to create a unique reference number for each ticket raised. It does this by looking at the last ID in the data source 'Tickets' and adding 1. Because we have a system where tickets can be closed and archived, it also checks the reference numbers from the 'Tickets Archive' list too see if it is going to duplicate (eg. Ticket ID 105 is archived - the app should read BOTH lists and see that ticket 2021-106 already exists so instead it will find the next available ID number and return that - ticket 2021-112). Screenshot below, I've tried to colour code it to make it clear:

1.png

DataCardValue1 (the ref input): 

If(TicketForm.Mode = FormMode.New, Year(Today())&"-"&NEWREF, Parent.Default)

NEWREF (green): 

If(TicketsArchiveGallery.Selected.IDStatic >= varID, TicketsArchiveGallery.Selected.IDStatic + 1, varID)

RefnoID (red): 

First(SortByColumns(Tickets, "ID", Descending).ID).ID+1

 varID is set on the CustomerTicket screen OnVisible:

Set(varID, Value(RefnoID.Text))

 

As you can see in the above screenshot, this seems to be working correctly, and it's returning a unique ID.

 

However when I save and publish this, I click 'Raise a new ticket' just as I do in the edit mode, and it returns the following

2.png

As you can see, this is now returning the Ticket Archive + 1, despite the fact that 112 (RefnoID - red) is the higher number and it should choose that one.

 

What makes this more frustrating is that if I click the cancel button it takes me back to a ticket gallery (below is the function on that button)

ResetForm(TicketForm); Refresh(Tickets); Navigate(JobListCustomer); ViewForm(TicketForm); Set(PopUpCancel, false);

and then come back into raising a new ticket, (below is the function on the new ticket button)

Refresh(Tickets); NewForm(TicketForm); Navigate(CustomerTicket);

 

it picks up the correct ID:

4.png

There is nothing in the OnVisible for the gallery screen to do this, and the OnVisible for the Ticket screen is:

 

Refresh('Tickets Archive'); Set(varID, Value(RefnoID.Text)); Refresh(Tickets)

 

Which should be picked up the first time it loads too.

 

I'm at a loss as to what is causing it to not pick up the correct ID and it is making the system unusable. 

 

I hope I've made the issue clear, if anyone needs any extra info please let me know - I'd really appreciate some help on this one.

1 ACCEPTED SOLUTION

Accepted Solutions
JR-BejeweledOne
Super User
Super User

Have you confirmed that varID has a value in it at the point the formula for NEWREF is firing the FIRST time?



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

View solution in original post

6 REPLIES 6
JR-BejeweledOne
Super User
Super User

Have you confirmed that varID has a value in it at the point the formula for NEWREF is firing the FIRST time?



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

View solution in original post

ah ha! That was quick. No it doesn't... 

5.png

Though it does when I'm editing, even if I start an entirely new session which is confusing. 

 

Looking at it, I'm guessing it's because I reference the RefnoID which is created the first time you come to this screen. Would it just be the case of moving that formula to the 'welcome' screen or something or is there a way I can get it to act as it does in edit mode in live mode (I've tried double navigation eg. the 'raise a new ticket' button navigates to the CustomerTicket screen, then back to the WelcomeScreen, then back to CustomerTicket with no luck)

Can you set the RefnoID in the App OnStart?



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

I don't think so because it's a text label rather than a variable, but I can put it on the home screen no problem and this is now working. 

 

I am now thinking how to ensure that no duplicates are created if two users open the app at the same time as this has also been highlighted as an issue and it seems the lookup I had in place is also not working.

 

Thank you for your help

 

JR-BejeweledOne
Super User
Super User

My favorite type of answers are the ones that not only provide a solution but lead me to find my own solutions.  I hope I have provided that for you.



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

I have a couple apps with similar needs as far as creating duplicates go.   How I solved those was to capture the ID information at save, so what you might need to do is set a variable with the RefnoID at save rather than where you are and then get set the new value at save also.   Present the view with the new number at the same time.

 

This is really the only way to prevent a duplicate number.



If you like this post, give it a Thumbs up. If it answered your question, Mark it as a Solution to enable other users find it.

Helpful resources

Announcements
PA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

PowerPlatform 768x460.png

Microsoft Learn

Check out our new Discover Your Career Path blog post series and get all the details.

Users online (2,234)