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 / Unique ID based on ini...
Power Apps
Answered

Unique ID based on initials of their name

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi all, new in powerapps. 

 

To set the scenario, I have two screens, a homepage, and an edit form. This form will be used internally by members of my team.  

On the homepage would be an 'add' symbol that navigates you to the Edit form, with a few generic fields, one of which is called referenceID, with varID assigned to the Default in data. 

 

What i have done is, onSelect of the 'add' symbol, is the line 

 

Set(varID, "A" & Text(Now(), "[$-en-US]yymmddhhmmss"))

 

I want to be able to change the "A" into initials of the name of whoever creates the form. 

 

i.e.

 

If John Doe uses the app and creates a form, on the edit form part, referenceID would be pre-filled in with JD12341234

If Richard Roe uses the app and creates a form, it would show RR12341234

 

 

Categories:
I have the same question (0)
  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Remove the formula you have on the add icon to set the variable and then make the following changes:

    Restore your Default property of the DataCard to : ThisItem.yourColumnName

    Then on the label (or whatever control you have in the datacard to display the value - I'm going to assume a read-only label called lblReferenceID) set the Text property to:

    Coalesce(Parent.Default,
     Concat(Split(User().FullName, " "), Left(Result, 1)) & Text(Now(), "yymmddhhmmss")
    )

    Then, for your Update property of the DataCard, set the formula to: lblReferenceID.Text

     

    I hope this is helpful for you.

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @RandyHayes, thanks for the speedy reply! 

     

    Your solution works as described; 

    I have removed the formula in the add icon to set the variable.

    Set the Default property of the Datacard to: ThisItem.Title 

    On a created label contained within the Datacard, modified the Text property to your formula. 

    Set the Update property of the Datacard accordingly. 

     

    There are no issues with the referenceID re-generating a new unique number each time i submit the form.

     

    However, i have a new issue after a little bit of testing. 

     

    Let me set the scenario again. I am now in the EditForm screen, with a uniquely generated referenceID, say, WD12341234, shown on my label. If i were to click a back() button, it will take me back to my homepage. 

     

    On the homepage, when i click the 'add' button, it will take me to the EditForm page, where the referenceID value persists as WD12341234. 

     

    Is there a way to make it so that the referenceID field regenerates a new set of unique ID, even when pressing back or resetting the form? 

     

    My 'add' button has the formula: ResetForm(EditForm); NewForm(EditForm); Navigate(EditForm, UnCover); Set(varEdit, Blank())

     

    My EditForm itself, under Item is: varEdit

     

  • Verified answer
    RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    So, the varEdit is not going to be relevant in your scenario as you are doing a NewForm function on the form. When you do that function, it uses the Defaults of the datasource as the underlying record (Item).  The only time that the Item property is relevant is if you are editing or viewing.

     

    So, the approach that I would suggest is to actually skip the NewForm and only do EditForm.  This may sound a little strange, but there is actually no difference between the two modes EXCEPT that NewForm creates a new record with the Defaults of the Datasource.  So, you can do the same thing with EditForm and the Item property.

     

    Consider this - if you keep the varEdit variable that you have and do the following:

        Set(varEdit, Defaults(yourDataSource));  EditForm(EditForm)

    It is the Equivalent of :  NewForm(EditForm)

     

    BUT...with the first formula, you can introduce values into the Default that you cannot do when using NewForm.

    So, with this in mind, change the following:

    - Set the Text Property on the label in your datacard to : Parent.Default

    - Change your add button formula to:

    Set(varEdit, 
     Patch(Defaults(yourDataSource), 
     {Title: Concat(Split(User().FullName, " "), Left(Result, 1)) & Text(Now(), "yymmddhhmmss")}
     )
    );
    EditForm(EditForm); //I'd consider changing the name of your EditForm to avoid confusion if that is in fact its name
    Navigate(OrderForm, UnCover)

    This will provide the same functionality and the Title (reference ID) will generate new numbers each time.

    Plus, if you are then editing an existing record, it will retain the properly recorded referenceID.

     

     

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    Hi @RandyHayes . Very thankful for the concise solution, it works perfectly!

     

    Kudos for the extra tidbit regarding NewForm and Editform!

     

  • RandyHayes Profile Picture
    76,299 Super User 2024 Season 1 on at

    @Anonymous 

    Happy to help!

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 June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
WarrenBelz Profile Picture

WarrenBelz 296 Most Valuable Professional

#2
11manish Profile Picture

11manish 224

#3
Valantis Profile Picture

Valantis 181

Last 30 days Overall leaderboard