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>
Now the result :