Question

Trying to create a unique ID(not sequential which is preferably an alpha numeric unique ID) for each row item added.

The same I have tried using an EXCEL formula, but how to integrate it with SharePoint list using JSOM and script editor web part. Also need to know how to bind the code to sharepoint list.

formula used in EXCEL sheet

=CONCATENATE(DEC2HEX(RANDBETWEEN(0,4294967295),8),"-",DEC2HEX(RANDBETWEEN(0,42949),4),"-",
Was it helpful?

Solution

The following example for your reference.

1.Create a custom list, add text field "GUID".

2.Add the code below into script editor web part in new form page.

<script src="https://code.jquery.com/jquery-1.12.4.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function (){
    var fieldTitle="GUID";
    $("input[title='"+fieldTitle+"']").val(buildGuid());
    $("input[title='"+fieldTitle+"']").attr("disabled", "disabled");
})
function buildGuid(){  
   return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function(c) {  
      var r = Math.random()*16|0, v = c === 'x' ? r : (r&0x3|0x8);  
      return v.toString(16);  
   });  
}
</script>

If you add item, we can see the GUID in the "GUID" field.

enter image description here

Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange
scroll top