web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / generate order number ...
Power Apps
Answered

generate order number and pass value to combo box

(0) ShareShare
ReportReport
Posted on by 820

Hi,

Within a button click i want to generate next order number from database and pass this value to combobox.

Combobox Items property is:

Sort(
Distinct(
Remontai,
'Užsakymo numeris'
),
Result
)

 

I can get the next number like this:

Concatenate("00000000",First(FirstN(Sort(Remontai,'Užsakymo numeris',Descending),1)).'Užsakymo numeris'+1)

Then i can patch this next number to table Remontai

But the tricky part is how after patching i make so that the combobox automaticaly gets  this value?

Categories:
I have the same question (0)
  • RusselThomas Profile Picture
    4,014 on at

    Hi @jja ,

    Are you wanting the last number that was used to come back after patching, or for the number you're using for the current patch to be passed to a combo?

    Can you explain a bit more about what you're trying to achieve?

     

    Every time you patch something, the entire record is returned back to PowerApps - this is like a confirmation of what was patched.  You can see this by saving the Patch() into a variable or collection.

    This is especially useful when you want to get something like a primary key back from something you just patched - for example, in SharePoint, the ID column is auto-populated and incremented, so you can't save it, but sometimes you want to know what it was for something you just created.  In this case;

     

    Set(patchResult, Patch(SPOList, Defaults(SPOList), {Title: "test"}))

     

    will return the entire record that was saved to SPO in the variable patchResult, including the autogenerated columns like ID, Created, etc.

    So you could then view something like the last patched ID using

    patchResult.ID

    Not sure if this would help you though?

    Kind regards,

    RT 

     

  • julijazas Profile Picture
    820 on at

    @RusselThomas 

    Let me explain bit more:

    In dataverse table 'Remontai' i have column 'Uzsakymo numeris'. Let's say last saved 'Uzsakymo numeris' value in table is 003. When presing button i want to find the last record then increment it by 1 which in this case will be 004 and automaticaly set this 004 to combobox1 already so this value is selected

  • AhmedSalih Profile Picture
    6,680 Moderator on at

    @jja, did you try to Refresh(Remontai) after the Patch function to populate the up-to-date combo-box values?

     

     

    Regards,
    Ahmed
    If my reply helped you, please give a 👍. And if it has solved your issue, please consider a 👍 & Accepting it as the Solution to help other members of the community find it more.

  • RusselThomas Profile Picture
    4,014 on at

    Hi @jja ,

    If your intent is for the combo to have the last number, you could run into issues when you list grows beyond your data row limit.  Last(source) will become the last record of the subset of data returned, up to a maximum of your data row limit (default 500, max 2000) rows.  

    So, if your list has 5000 rows and your data row limit is 500, Last(source) will only ever return the 500th row.

     

    A better way to get this might be to instead select the first of the list when its sorted by descending values.  Because SortByColumns(source, "column", Descending) is delegable, you can be sure you will always get the last record in the first place.

     

    Then, to set the DefaultSelectedItems: property of your combo to the last  'Uzsakymo numeris', you just have to specify a record that exists in the ComboBox Items: output - to make this easier, just make sure your filter statements for both Items: and DefaultSelectedItems: return the same subset of data.

    Try this - if your Items: property for your combo is;

     

    SortByColumns(Remontai, "Uzsakymo numeris", Descending)

     

    then your DefaultSelectedItems: property on your combo would be;

     

    First(SortByColumns(Remontai, "Uzsakymo numeris", Descending))

     

    Lastly, capturing data to a source in Power Apps automatically refreshes the source for that user session - so if you're the only one running this app you wouldn't need to Refresh the source to see your combo update after a patch - however, if someone else is running this app at the same time and adding records, then your session wouldn't know about it until it Refreshes, either by saving data to the source, or using the Refresh() function - be careful using a field value that is generated by PowerApps based on the Last() record of a source, because it might not be the last record when you run your Patch() and you could end up with duplicate auto-gen'd numbers...

    Hope this helps,

    RT

  • julijazas Profile Picture
    820 on at

    @RusselThomas 

    Ok i understood according delegation but i want the 'Uzsakymo numeris' to appear in the combobox only when it is generated as new 'Uzsakymo numeris' so the sequence like this"

    User press button-->Uzsakymo numeris is patched to datasource--> patched 'Uzsakymo numeris' is selected in combobox

  • julijazas Profile Picture
    820 on at

    @AhmedSalih 

    Refresh happens everytime you execute Patch - no need to use Refresh. Number appears in combobox dropdown but my issue is i want whenewer i patch new number it gets automaticaly autoselected in that combobox

  • Verified answer
    AhmedSalih Profile Picture
    6,680 Moderator on at

    @jja, in DefaultSelectedItems property of your combo-box, use this formula: 

     

    First(SortByColumn(Remontai, "CreatedOnDate", SortOrder.Descending))

    Change the CreatedOnDate to your column name where the creation datatime is stored.

     

    Regards,
    Ahmed
    If my reply helped you, please give a 👍. And if it has solved your issue, please consider a  👍 & Accepting it as the Solution to help other members of the community find it more.

     

     

     

  • julijazas Profile Picture
    820 on at

    @AhmedSalih 

    But on your scenario i will get the number selected in combobox whenewer i start the app and i want it to be selected only when user hits button where patch creates this new number in database and only then i want it to be automaticaly  selected in combobox

  • AhmedSalih Profile Picture
    6,680 Moderator on at

    @jja, add a local variable to the button you hit to Patch: UpdateContext({lclCombBoxValueUpdated: true}) and then in the DefaultSelectedItems = If(lclCombBoxValueUpdated, First(SortByColumn(Remontai, "CreatedOnDate", SortOrder.Descending)))

     

     

    Regards,
    Ahmed
    If my reply helped you, please give a 👍. And if it has solved your issue, please consider a  👍 & Accepting it as the Solution to help other members of the community find it more.

     

  • RusselThomas Profile Picture
    4,014 on at

    I'm curious as to what the Items: property of your combo is...but Ahmed's solution should work anyway.

    Kind regards,

    RT

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 329 Most Valuable Professional

#2
11manish Profile Picture

11manish 209 Super User 2026 Season 2

#3
Mohsin Ali Profile Picture

Mohsin Ali 179

Last 30 days Overall leaderboard