There are multiple requirements for Unique ticket number generation in SharePoint Lists.
It can be achieved by below JavaScript code and calling it content editor/Script Editor in NewForm.aspx
It generates Random ticket number along with Year and month value extracted from client machine's Year and Month parameter.
Replace "COLUMN_NAME" with the Display Value of the column name which needs to be written with the Unique ticket number generation. e.g. your Column field is Ticket Number then
var columnName = "Ticket Number";
Using little modification same can be utilized in jsLink of the New Item section of the List as well.
This ticket number gives user easy interpretation of ticket detail.
Prefix :- This is specify source of ticket generation e.g. for SharePoint online
Year-Month :- This is give the detail when the ticket was created
Ticket Number :- Unique ticket number for tracking of tickets.
It can be achieved by below JavaScript code and calling it content editor/Script Editor in NewForm.aspx
It generates Random ticket number along with Year and month value extracted from client machine's Year and Month parameter.
Replace "COLUMN_NAME" with the Display Value of the column name which needs to be written with the Unique ticket number generation. e.g. your Column field is Ticket Number then
var columnName = "Ticket Number";
Using little modification same can be utilized in jsLink of the New Item section of the List as well.
This ticket number gives user easy interpretation of ticket detail.
Prefix :- This is specify source of ticket generation e.g. for SharePoint online
Year-Month :- This is give the detail when the ticket was created
Ticket Number :- Unique ticket number for tracking of tickets.
<!-- Sricpt for Random ticket generation method Starts-->
<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">
</script>
<script type="text/javascript">
var columnName = "COLUMN_NAME";
var prefixVal = "TicketNo";
$(document).ready(function () {
var listName = _spPageContextInfo.listTitle;
// SP.PageContextInfo.get_pageListId();
var eleReq = $("input[title='" + columnName+"']"); // Get Element to update the
var dateTime = new Date();
getLastItemId();
function getLastItemId() {
var caml = "<View><Query><Where>"
+ "<Geq><FieldRef Name='ID' /><Value Type='Integer'>"
+ 0 + "</Value></Geq></Where>"
+ "<OrderBy><FieldRef Name='ID' Ascending='False' /></OrderBy>"
+ "</Query><RowLimit>1</RowLimit></View>";
var ctx = SP.ClientContext.get_current();
var web = ctx.get_web();
var list = web.get_lists().getByTitle(listName);
var query = new SP.CamlQuery();
query.set_viewXml(caml);
var items = list.getItems(query);
ctx.load(items);
ctx.executeQueryAsync(function () {
// success actions
var id = "00000";
var enumerator = items.getEnumerator();
enumerator.moveNext();
var item = enumerator.get_current();
try {
id = item.get_id();
}
catch (exception)
{ // For first item it will return nothing.. thus it is set to 00000
id = "00000";
}
var fiveDigitId = "00000";
fiveDigitId = fiveDigitId.substring(id.toString().length) + id;
var strRedId = prefixVal + dateTime.toISOString().slice(0, 8).replace(/-/g, "") + fiveDigitId;//
eleReq.val(strRedId);
}, function () {
var strRedId = prefixVal + dateTime.toISOString().slice(0, 8).replace(/-/g, "") + Math.floor((Math.random() * 10000) + 1);
eleReq.val(strRedId);
});
}
});
</script>
<!-- Sricpt for Random ticket generation method ENDS-->