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 / how to set Automatic s...
Power Apps
Answered

how to set Automatic sequence number in sharepoint List whenever new row is created

(0) ShareShare
ReportReport
Posted on by 57

how to set Automatic sequence number in sharepoint List whenever new row is created

Categories:
I have the same question (0)
  • Verified answer
    Drrickryp Profile Picture
    Super User 2024 Season 1 on at

    Hi @Paul-2020 

    All SharePoint lists already have a hidden but accessible Id column that generates a sequential number. It can be unhidden in SharePoint. Ref. https://sharepointmaven.com/how-to-add-a-unique-identifier-to-a-sharepoint-list-or-library/

  • Max44 Profile Picture
    223 on at

    You can do this in JavaScript by using the SPUtility.js library

    PS, in this exemple I have used SharePoint 2010, but it's the same with SP 2013

    As example I have created a simple list 'sequential number' with:

    • Title (simple text).
    • Occurrence # (simple text), this is our auto increment id

    Every list has three default forms to add, display and edit items, we are going to edit this forms to achieve our goal.

     

    Before beginning the modification, download the SPUtility.js and the JQuery than upload the two file to SharePoint for example on the Shared Documents Library.

    Edit the ‘Default New Form’ and add a Content Editor Web part

     

    Edit the Html content the web part and past the code below :

    ​<script src="/Shared%20Documents/jquery-1.10.2.min.js"></script>
    <script src="/Shared%20Documents/sputility.min.js"></script>
    <script>
    
     // Get the current Site
     var siteUrl = '/';
    
     function retrieveListItems() {
    
     var clientContext = new SP.ClientContext(siteUrl);
     // Get the liste instance
     var oList = clientContext.get_web().get_lists().getByTitle('sequential number');
    
     var camlQuery = new SP.CamlQuery();
    
     // Get only the last element camlQuery.set_viewXml('<View><Query><OrderBy><FieldRef Name=\'ID\' Ascending=\'False\' /></OrderBy></Query><RowLimit>1</RowLimit></View>');
     this.collListItem = oList.getItems(camlQuery); clientContext.load(collListItem); clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed)); 
    
     }
    
     function onQuerySucceeded(sender, args) {
    
     var listItemInfo = '';
    
     var listItemEnumerator = collListItem.getEnumerator();
    
     while (listItemEnumerator.moveNext()) {
     var oListItem = listItemEnumerator.get_current();
    
     var listItemInfovalue = oListItem.get_item('Occurrence_x0020__x0023_');
    
    
     // Based in you request the id is : 14-00001
    
     // Split the first
     var res = listItemInfovalue.split("-"); console.log(res[1]);
    
     // increment the index
     var newId = parseInt(res[1])+1;
    
     // create the new id
     SPUtility.GetSPField('Occurrence #').SetValue(res[0] + '-' + pad(newId, 5) );
     } console.log(listItemInfo.toString());
     }
    
     function onQueryFailed(sender, args) { alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace()); 
     } 
    
    
     // Create new id with fixed size : 
     // exp : 00001, 00001
    
     // num : is the number
     // size : is the number size
     function pad(num, size) {
     var s = num+"";
     while (s.length < size) s = "0" + s;
     return s;
     }
    $(document).ready(function(){
     ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js"); 
     });
    
    </script>
     

    I hope this helps!

    Admin

    apps4rent | o365cloudexperts | clouddesktoponline

  • Max44 Profile Picture
    223 on at

    You can do this in JavaScript by using the SPUtility.js library

    PS, in this exemple I have used SharePoint 2010, but it's the same with SP 2013

    As example I have created a simple list 'sequential number' with:

    Title (simple text).
    Occurrence # (simple text), this is our auto increment id
    Every list has three default forms to add, display and edit items, we are going to edit this forms to achieve our goal.

    enter image description here

    Before beginning the modification, download the SPUtility.js and the JQuery than upload the two file to SharePoint for example on the Shared Documents Library.

    Edit the ‘Default New Form’ and add a Content Editor Web part

     

    Edit the Html content the web part and past the code below :

    ​<script src="/Shared%20Documents/jquery-1.10.2.min.js"></script>
    <script src="/Shared%20Documents/sputility.min.js"></script>
    <script>

    // Get the current Site
    var siteUrl = '/';

    function retrieveListItems() {

    var clientContext = new SP.ClientContext(siteUrl);
    // Get the liste instance
    var oList = clientContext.get_web().get_lists().getByTitle('sequential number');

    var camlQuery = new SP.CamlQuery();

    // Get only the last element
    camlQuery.set_viewXml('<View><Query><OrderBy><FieldRef Name=\'ID\' Ascending=\'False\' /></OrderBy></Query><RowLimit>1</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

    }

    function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();

    var listItemInfovalue = oListItem.get_item('Occurrence_x0020__x0023_');


    // Based in you request the id is : 14-00001

    // Split the first
    var res = listItemInfovalue.split("-");

    console.log(res[1]);

    // increment the index
    var newId = parseInt(res[1])+1;

    // create the new id
    SPUtility.GetSPField('Occurrence #').SetValue(res[0] + '-' + pad(newId, 5) );
    }

    console.log(listItemInfo.toString());
    }

    function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }


    // Create new id with fixed size :
    // exp : 00001, 00001

    // num : is the number
    // size : is the number size
    function pad(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
    }


    $(document).ready(function(){
    ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
    });

    </script>

     

    I hope this is helpful.

    Admin

    apps4rent | o365cloudexperts | clouddesktoponline

  • Max44 Profile Picture
    223 on at

    You can do this in JavaScript by using the SPUtility.js library

    PS, in this exemple I have used SharePoint 2010, but it's the same with SP 2013

    As example I have created a simple list 'sequential number' with:

    Title (simple text).
    Occurrence # (simple text), this is our auto increment id
    Every list has three default forms to add, display and edit items, we are going to edit this forms to achieve our goal.

    enter image description here

    Before beginning the modification, download the SPUtility.js and the JQuery than upload the two file to SharePoint for example on the Shared Documents Library.

    Edit the ‘Default New Form’ and add a Content Editor Web part

    enter image description here

    Edit the Html content the web part and past the code below :

    ​<script src="/Shared%20Documents/jquery-1.10.2.min.js"></script>
    <script src="/Shared%20Documents/sputility.min.js"></script>
    <script>

    // Get the current Site
    var siteUrl = '/';

    function retrieveListItems() {

    var clientContext = new SP.ClientContext(siteUrl);
    // Get the liste instance
    var oList = clientContext.get_web().get_lists().getByTitle('sequential number');

    var camlQuery = new SP.CamlQuery();

    // Get only the last element
    camlQuery.set_viewXml('<View><Query><OrderBy><FieldRef Name=\'ID\' Ascending=\'False\' /></OrderBy></Query><RowLimit>1</RowLimit></View>');
    this.collListItem = oList.getItems(camlQuery);

    clientContext.load(collListItem);

    clientContext.executeQueryAsync(Function.createDelegate(this, this.onQuerySucceeded), Function.createDelegate(this, this.onQueryFailed));

    }

    function onQuerySucceeded(sender, args) {

    var listItemInfo = '';

    var listItemEnumerator = collListItem.getEnumerator();

    while (listItemEnumerator.moveNext()) {
    var oListItem = listItemEnumerator.get_current();

    var listItemInfovalue = oListItem.get_item('Occurrence_x0020__x0023_');


    // Based in you request the id is : 14-00001

    // Split the first
    var res = listItemInfovalue.split("-");

    console.log(res[1]);

    // increment the index
    var newId = parseInt(res[1])+1;

    // create the new id
    SPUtility.GetSPField('Occurrence #').SetValue(res[0] + '-' + pad(newId, 5) );
    }

    console.log(listItemInfo.toString());
    }

    function onQueryFailed(sender, args) {
    alert('Request failed. ' + args.get_message() + '\n' + args.get_stackTrace());
    }


    // Create new id with fixed size :
    // exp : 00001, 00001

    // num : is the number
    // size : is the number size
    function pad(num, size) {
    var s = num+"";
    while (s.length < size) s = "0" + s;
    return s;
    }


    $(document).ready(function(){
    ExecuteOrDelayUntilScriptLoaded(retrieveListItems, "sp.js");
    });

    </script>
    Now the result :

    enter image description here

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Apps

#1
Valantis Profile Picture

Valantis 413

#2
WarrenBelz Profile Picture

WarrenBelz 355 Most Valuable Professional

#3
timl Profile Picture

timl 315 Super User 2026 Season 1

Last 30 days Overall leaderboard