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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Apps / Auto Increment last va...
Power Apps
Unanswered

Auto Increment last value in data source

(1) ShareShare
ReportReport
Posted on by 35

I am currently having an issue. I have a Home screen with buttons (one of the buttons is to create a new record) once clicked, it goes to another screen, but I would like one of the cards to automatically produce a number +1 of the record/data sours (in this case its a list I created with several columns, but I only need one card to have auto-increment. I hope I am making sense. (I used the following on the second page once the button is clicked on the home screen  If(Last('RMA Register').RmaNumber+1,Parent.Default))

(Thank you everyone who has responded)

==>I updated the photo below. The button fx is as follows    Navigate( NewRma, Fade);  I think I need to add to this before it goes to the other page based off the response below. 

 

 

Screenshot 2023-08-11 at 5.21.58 PM.png

Screenshot 2023-08-11 at 2.08.23 PM.pngScreenshot 2023-08-11 at 2.13.47 PM.png

Categories:
I have the same question (0)
  • Verified answer
    poweractivate Profile Picture
    11,078 Most Valuable Professional on at

     

    If(!IsBlank(Last('RMA Register').RmaNumber), Last('RMA Register').RmaNumber + 1, 1)
    

     

    Try this. If expects true or false, not a number, you passed in Last('RMA Register').RmaNumber+1 directly into the If which is not correct. See if it helps @ezraveee 

    If it works, please make any other adjustments as appropriate to the above formula.

  • madlad Profile Picture
    2,637 Moderator on at

    @ezraveee what's the error you're getting?

    I notice in your If function, you're using NewRMA as the true/false value. 

     

    If this is where the error is, you could replace this with "FormName.Mode = FormMode.New" to check if it's a new record being created.

     

    Hope this helps!

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @ezraveee Oh I see I think you provide different formula in the post than in the screenshot.

    Let's check the formula in the screenshot

     

    For NewRma how are you determining it?


    You should try this:
    OnSelect of New Rma button

     

    UpdateContext({varFormMode:FormMode.New})

     

    and then from where you edit existing record:

     

    UpdateContext({varFormMode:FormMode.Edit})

     

    make sure DefaultMode of your Form is:

     

    varFormMode

     

    Then try this for your existing datacard control property

     

    If(varFormMode = FormMode.New, Last('RMA Register').RmaNumber + 1, Parent.Default)

     

    Does it work now @ezraveee ? 

    You can also try the approach by @madlad if you prefer, however, you still need to determine the FormMode somehow. If you are both needing to set the FormMode AND use that set FormMode to determine the action to take, a context variable may still be better, but you may use either approach as you see fit though.

  • madlad Profile Picture
    2,637 Moderator on at

    @poweractivate 

    I believe you can access the form's mode from outside of the control? Unless I'm mistaking what you mean?

    Using "FormName.Mode" will access it - see documentation here 

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @madlad 
    Yes that is correct, it's possible to access it. 

    However if @ezraveee is happening to want to both determine and use the FormMode anyway dynamically at the same time, then it may be better to use a context variable that is placed in DefaultMode property of the Form, (global variable using Set() if the variable is re-used in more than one Screen, but I assume UpdateContext as I assume it's only needed for the Screen) and then check on the context variable. However in case it's desired to check on the specific FormMode of the Form your approach should work for that.

  • ezraveee Profile Picture
    35 on at

    I think My error is steaming from the home screen. When I click on the New RMA button its a navigationScreenshot 2023-08-11 at 5.25.21 PM.png (Fx) 

  • ezraveee Profile Picture
    35 on at

    Thank you for the response. I think my issue is steaming from the home screen button. Screenshot 2023-08-11 at 5.26.58 PM.png

  • poweractivate Profile Picture
    11,078 Most Valuable Professional on at

    @ezraveee 
    Yes if you are trying to use the variable approach I gave you should change this formula in the OnSelect of the New Rma button to 

    Navigate(NewRma,SceenTransition.Fade);UpdateContext({varFormMode:FormMode.New})

     See if it helps @ezraveee 

  • ezraveee Profile Picture
    35 on at

    I keep getting an error.  Not sure what to do 

     

     

    Screenshot 2023-08-11 at 6.30.26 PM.png

  • Verified answer
    madlad Profile Picture
    2,637 Moderator on at

     @ezraveee - it looks like perhaps the variable has not been set or referenced correctly here.

    If you only need this code for setting the default on that item, you can use:

    If(*FormName*.Mode = FormMode.New, Last('RMA Register').RmaNumber + 1, Parent.Default)

    just make sure to swap in the form's name.

     

     

    If you will also be using this to set the form's mode ever, or if you find it more simple, just confirm that the variable is being defined and referenced correctly as per @poweractivate's prior suggestion. Perhaps also send a screenshot of where you navigate and define the variable if it still doesn't work, that could maybe give more insight.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 717 Most Valuable Professional

#2
Michael E. Gernaey Profile Picture

Michael E. Gernaey 329 Super User 2025 Season 2

#3
Power Platform 1919 Profile Picture

Power Platform 1919 268

Last 30 days Overall leaderboard