cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
SteCoxy
Helper I
Helper I

How to generate a custom prefix unique ID

Hello, I would like some guidance on how to generate a unique ID that has a custom prefix when a new row is created in a MS List. I think it would be a formula of some sort but I'm not sure how to go about this.

 

The convention I'm looking for would be something like:

 

D&I-000001

D&I-000002

D&I-000003

etc

 

Any advice would be much appreciated.

16 REPLIES 16
DamoBird365
Employee
Employee

Hi @SteCoxy 

 

I've an article on this here Unique IDs and pad a string - DamoBird365

 

Please let me know if you need any further explanation.

 

Please consider accepting my answer as a solution if it helps to solve your problem.

Cheers
Damien

Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts, or take a look at my website. Thanks

Hi Damien

 

Thank you for taking the time to reply to my query. 

 

I won't lie - I'm a complete novice when it comes to this kind of thing, so please forgive my ignorance here.

 

I've looked at your help guide and it appears more complex than what I'm looking for - I don't need for the function to pull any data from any other column for the prefix. 

 

I simply need every time a new row is created (from the form submission that is made) for the unique ID column to have the prefix starting with D&I then a hyphen and then 5 zeros, before incrementally going up by 1, 2, 3 etc:

D&I-000001

D&I-000002

D&I-000003 etc. 

 

Any ideas on what formula this would require?

HI @SteCoxy 

 

If you are creating an item in a list every time a form submission is made, you need to get the last id and increment by 1, before prepending your fixed string.  

 

In my article I use get item to get the last known ID as you need to know the last unique id before creating the next one.  Some folk use a separate list, others use the list item ID but you need to use something.

 

DamoBird365_0-1643817677879.png

I also have two columns to keep track of the running ID and the prepended ID but you could use replace() to remove your prefix to allow you to increment on the integer, it's just a bit more work.

 

DamoBird365_2-1643817763371.png

Above, assuming the column is called InvoiceID, you can add 1 on to the last number.

add(int(first(outputs(‘Get_items’)?[‘body/value’])?[‘InvoiceId’]),1)

 

You then need to pad with 0's:

concat(substring(‘00000’, 1, sub(5, length(string(outputs(‘InvoiceID’))))),outputs(‘InvoiceID’))

 

Then when you create your item, you can add 

D&I- 

alongside the output (instead of "Invoice" in the Title) from the above expression in compose.

 

DamoBird365_3-1643817957625.png

 

If this doesn't make sense, please explain where you get stuck.

 

Damien

Cheers Damien, thank you for coming back to me here. I will give this a go and see if I can figure it out. All of this, at the very least, is certainly helping to improve my knowledge and skill base 

SteCoxy
Helper I
Helper I

Hi Damien, again, please excuse my ignorence here - particularly if your solution covers exactly this, but something that's just come into my head is: does this have logic involved to reduce the number of zeros when it gets to 9, 99, 999 etc as below:

D&I-000001

...

D&I-000009

D&I-000010 rather than

D&I-0000010

SteCoxy
Helper I
Helper I

Also, does it matter if I wish to create this based upon the system column called ID (read only), that autopopulates the cell incrementally: 1, 2, 3, 4 etc:

 

Screenshot 2022-02-03 at 15.46.08.png

Hi @SteCoxy 

 

Yes, that is what length and substring do, let me explain.

 

concat(substring(‘00000’, 1, sub(5, length(string(outputs(‘InvoiceID’))))),outputs(‘InvoiceID’))

 

This will concatenate upto 5 0's based on the substring starting at position 1, and ending at length of the invoice ID.

 

Therefore if invoiceID is 123, it is length 3.  The substring of 00000 from position 1 to 3 is 00 and concat the two, you get 00123.

 

Try the following in a compose:

concat('ABCD-',substring('00000', 1, sub(5, length('123'))),'123')

 

DamoBird365_1-1643903770225.png

 

You could use ID of the item but there are pros/cons.  It cannot be reset.  Delete an item, you loose that ID.  You could therefore get the last known ID of an item, increment by 1, pad with 0's, and prepend the string.

 

Hope that has been useful.

 

Damien

 

Hi Damien,

 

I'm giving your solution an attempt but I'm falling at the first hurdle, sorry!

 

I'm getting an "the expression is invalid" error message, unfortunately:

 

Screenshot 2022-02-03 at 17.12.10.png

I entered the following: add(int(first(outputs(‘Get_items’)?[‘body/value’])?[‘ID’]),1)

 

I'm not sure if it helps things but this is a brand new project, so there's currently only dummy data (about 10 rows) in this MS List, so nothing in there has any valid last ID. I think what's confusing me is on your website it's based upon the Title column, but my title column is "Programme Name", so this wouldn't be suitable (as it's purely words). That's why I thought having a system generated ID column (1, 2, 3, etc) might make it easier for the string to be created, as it's based on, in effect, the row number in the list that is going up incrementally each time a new item/row is created. 

 

Sorry to be taking up your time here, but any pointers on how best to achieve this would be much appreciated.

HI @SteCoxy 

 

You'll need to get your order by in get items correct, not sure where the id 2 comes from.  If you have a column called "id 2", you will need to get the internal name.  You need to go into list settings (top right cog and list settings) and then select the column in question.  In the address bar you will see the internal name

 

DamoBird365_3-1643915924460.png

 

For the flow, this is what you are looking for:

DamoBird365_0-1643915711744.png

 

add(int(first(outputs('Get_items')?['body/value'])?['ID']),1)

concat('ABCD-',substring('00000', 1, sub(5, length(string(outputs('compose'))))),outputs('compose'))

 

Output

DamoBird365_2-1643915766129.png

 

Please consider accepting my answer as a solution if it helps to solve your problem.

Cheers
Damien

Please take a look and subscribe to my YouTube Channel for more Power Platform ideas and concepts, or take a look at my website. Thanks

SteCoxy
Helper I
Helper I

Hi Damien,

 

I think I'm making inroads here, albeit slowly but surely! 

 

I've got as far as testing this out, so I've certainly made further progress than earlier, but I'm getting the following errors in the flow details:

 

 

Just to clarify also, the formula - I'm looking for this to populate in a new column called "D&I Unique ID", but is it based upon the system generated ID column? 

Screenshot 2022-02-03 at 19.50.31.png

I think I'm 3/4 there now Damien and I REALLY appreciate you helping me out. I know your patience must be getting tested to within an ounce of its limits, but I really feel like you're helping me massively to learn. 

Hi @SteCoxy 

 

Your order by in get items is showing 15?

 

It should be ID desc

 

I am glad you're learning - that's the aim of this forum for sure and hopefully you'll be able to teach others one day in return 🙂

 

Damien

 

is desc a function or do I literally just type it after ID?  

 

Also, how does it know to add this unique ID into the below column, as the formula doesn't seem to make any reference to it?

Screenshot 2022-02-04 at 09.59.29.png

DamoBird365
Employee
Employee

Hi @SteCoxy 

 

literally type

 

id desc

 

id is the column name and desc means descending, asc would be ascending. You want the top id of 1 based on descending order. 

don’t use the dynamic value for id, type the string Id.

 

Damien

 

 This is the latest error I've got after trying to test it out. 

I've had another go at this but I'm getting a different error message following testing:

 

 

 

I'm wondering if I could pick your brains again please Damien?

 

This is formula used in the first compose action: 

add(int(first(outputs('Get_items')?['body/value'])?['D&I Unique ID']),1)
 
This is the formula used in the second compose action:
concat('ABCD-',substring('00000', 1, sub(5, length(string(outputs('compose'))))),outputs('compose'))
SteCoxy
Helper I
Helper I

Further to the above, I've changed the formula to: 

 

add(int(first(outputs('Get_items')?['body/value'])?['ID']),1)

 

and it now says it has been successful BUT there is no entry in the D&I Unique ID column:

 

Screenshot 2022-02-08 at 14.03.17.png

So it's not working the way I thought i.e. I was hoping that the D&I Unique Id column would populate using the ID from the system column but with a DI000001 prefix. Any ideas to point me in the right direction would be much appreciated.

Helpful resources

Announcements

Calling all User Group Leaders and Super Users! Mark Your Calendars for the next Community Ambassador Call on May 9th!

This month's Community Ambassador call is on May 9th at 9a & 3p PDT. Please keep an eye out in your private messages and Teams channels for your invitation. There are lots of exciting updates coming to the Community, and we have some exclusive opportunities to share with you! As always, we'll also review regular updates for User Groups, Super Users, and share general information about what's going on in the Community.     Be sure to register & we hope to see all of you there!

April 2024 Community Newsletter

We're pleased to share the April Community Newsletter, where we highlight the latest news, product releases, upcoming events, and the amazing work of our outstanding Community members.   If you're new to the Community, please make sure to follow the latest News & Announcements and check out the Community on LinkedIn as well! It's the best way to stay up-to-date with all the news from across Microsoft Power Platform and beyond.    COMMUNITY HIGHLIGHTS   Check out the most active community members of the last month! These hardworking members are posting regularly, answering questions, kudos, and providing top solutions in their communities. We are so thankful for each of you--keep up the great work! If you hope to see your name here next month, follow these awesome community members to see what they do!   Power AppsPower AutomateCopilot StudioPower PagesWarrenBelzDeenujialexander2523ragavanrajanLaurensMManishSolankiMattJimisonLucas001AmikcapuanodanilostephenrobertOliverRodriguestimlAndrewJManikandanSFubarmmbr1606VishnuReddy1997theMacResolutionsVishalJhaveriVictorIvanidzejsrandhawahagrua33ikExpiscornovusFGuerrero1PowerAddictgulshankhuranaANBExpiscornovusprathyooSpongYeNived_Nambiardeeksha15795apangelesGochixgrantjenkinsvasu24Mfon   LATEST NEWS   Business Applications Launch Event - On Demand In case you missed the Business Applications Launch Event, you can now catch up on all the announcements and watch the entire event on-demand inside Charles Lamanna's latest cloud blog.   This is your one stop shop for all the latest Copilot features across Power Platform and #Dynamics365, including first-hand looks at how companies such as Lenovo, Sonepar, Ford Motor Company, Omnicom and more are using these new capabilities in transformative ways. Click the image below to watch today!   Power Platform Community Conference 2024 is here! It's time to look forward to the next installment of the Power Platform Community Conference, which takes place this year on 18-20th September 2024 at the MGM Grand in Las Vegas!   Come and be inspired by Microsoft senior thought leaders and the engineers behind the #PowerPlatform, with Charles Lamanna, Sangya Singh, Ryan Cunningham, Kim Manis, Nirav Shah, Omar Aftab and Leon Welicki already confirmed to speak. You'll also be able to learn from industry experts and Microsoft MVPs who are dedicated to bridging the gap between humanity and technology. These include the likes of Lisa Crosbie, Victor Dantas, Kristine Kolodziejski, David Yack, Daniel Christian, Miguel Félix, and Mats Necker, with many more to be announced over the coming weeks.   Click here to watch our brand-new sizzle reel for #PPCC24 or click the image below to find out more about registration. See you in Vegas!       Power Up Program Announces New Video-Based Learning Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram. These include a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the image below to find out more!   UPCOMING EVENTS Microsoft Build - Seattle and Online - 21-23rd May 2024 Taking place on 21-23rd May 2024 both online and in Seattle, this is the perfect event to learn more about low code development, creating copilots, cloud platforms, and so much more to help you unleash the power of AI.   There's a serious wealth of talent speaking across the three days, including the likes of Satya Nadella, Amanda K. Silver, Scott Guthrie, Sarah Bird, Charles Lamanna, Miti J., Kevin Scott, Asha Sharma, Rajesh Jha, Arun Ulag, Clay Wesener, and many more.   And don't worry if you can't make it to Seattle, the event will be online and totally free to join. Click the image below to register for #MSBuild today!   European Collab Summit - Germany - 14-16th May 2024 The clock is counting down to the amazing European Collaboration Summit, which takes place in Germany May 14-16, 2024. #CollabSummit2024 is designed to provide cutting-edge insights and best practices into Power Platform, Microsoft 365, Teams, Viva, and so much more. There's a whole host of experts speakers across the three-day event, including the likes of Vesa Juvonen, Laurie Pottmeyer, Dan Holme, Mark Kashman, Dona Sarkar, Gavin Barron, Emily Mancini, Martina Grom, Ahmad Najjar, Liz Sundet, Nikki Chapple, Sara Fennah, Seb Matthews, Tobias Martin, Zoe Wilson, Fabian Williams, and many more.   Click the image below to find out more about #ECS2024 and register today!     Microsoft 365 & Power Platform Conference - Seattle - 3-7th June If you're looking to turbo boost your Power Platform skills this year, why not take a look at everything TechCon365 has to offer at the Seattle Convention Center on June 3-7, 2024.   This amazing 3-day conference (with 2 optional days of workshops) offers over 130 sessions across multiple tracks, alongside 25 workshops presented by Power Platform, Microsoft 365, Microsoft Teams, Viva, Azure, Copilot and AI experts. There's a great array of speakers, including the likes of Nirav Shah, Naomi Moneypenny, Jason Himmelstein, Heather Cook, Karuana Gatimu, Mark Kashman, Michelle Gilbert, Taiki Y., Kristi K., Nate Chamberlain, Julie Koesmarno, Daniel Glenn, Sarah Haase, Marc Windle, Amit Vasu, Joanne C Klein, Agnes Molnar, and many more.   Click the image below for more #Techcon365 intel and register today!     For more events, click the image below to visit the Microsoft Community Days website.      

Tuesday Tip | Update Your Community Profile Today!

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   We're excited to announce that updating your community profile has never been easier! Keeping your profile up to date is essential for staying connected and engaged with the community.   Check out the following Support Articles with these topics: Accessing Your Community ProfileRetrieving Your Profile URLUpdating Your Community Profile Time ZoneChanging Your Community Profile Picture (Avatar)Setting Your Date Display Preferences Click on your community link for more information: Power Apps, Power Automate, Power Pages, Copilot Studio   Thank you for being an active part of our community. Your contributions make a difference! Best Regards, The Community Management Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Super User of the Month | Ahmed Salih

We're thrilled to announce that Ahmed Salih is our Super User of the Month for April 2024. Ahmed has been one of our most active Super Users this year--in fact, he kicked off the year in our Community with this great video reminder of why being a Super User has been so important to him!   Ahmed is the Senior Power Platform Architect at Saint Jude's Children's Research Hospital in Memphis. He's been a Super User for two seasons and is also a Microsoft MVP! He's celebrating his 3rd year being active in the Community--and he's received more than 500 kudos while authoring nearly 300 solutions. Ahmed's contributions to the Super User in Training program has been invaluable, with his most recent session with SUIT highlighting an incredible amount of best practices and tips that have helped him achieve his success.   Ahmed's infectious enthusiasm and boundless energy are a key reason why so many Community members appreciate how he brings his personality--and expertise--to every interaction. With all the solutions he provides, his willingness to help the Community learn more about Power Platform, and his sheer joy in life, we are pleased to celebrate Ahmed and all his contributions! You can find him in the Community and on LinkedIn. Congratulations, Ahmed--thank you for being a SUPER user!

Tuesday Tip: Getting Started with Private Messages & Macros

Welcome to TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   This Week's Tip: Private Messaging & Macros in Power Apps Community   Do you want to enhance your communication in the Community and streamline your interactions? One of the best ways to do this is to ensure you are using Private Messaging--and the ever-handy macros that are available to you as a Community member!   Our Knowledge Base article about private messaging and macros is the best place to find out more. Check it out today and discover some key tips and tricks when it comes to messages and macros:   Private Messaging: Learn how to enable private messages in your community profile and ensure you’re connected with other community membersMacros Explained: Discover the convenience of macros—prewritten text snippets that save time when posting in forums or sending private messagesCreating Macros: Follow simple steps to create your own macros for efficient communication within the Power Apps CommunityUsage Guide: Understand how to apply macros in posts and private messages, enhancing your interaction with the Community For detailed instructions and more information, visit the full page in your community today:Power Apps: Enabling Private Messaging & How to Use Macros (Power Apps)Power Automate: Enabling Private Messaging & How to Use Macros (Power Automate)  Copilot Studio: Enabling Private Messaging &How to Use Macros (Copilot Studio) Power Pages: Enabling Private Messaging & How to Use Macros (Power Pages)

Users online (5,682)