Autonumber list items with DFFS

Forums Requests Autonumber list items with DFFS

This topic contains 3 replies, has 2 voices, and was last updated by  Alexander Bautz 1 year ago.

  • Author
    Posts
  • #12690

    avala
    Participant

    Curious if creating a auto number feature in DFFS is something you’d be interested in. We currently use a Nintex workflow to query a list and auto-increment list items. Typical naming conventions start at FDC 1,001, FDC 1,002, etc to properly sort in a SharePoint list.

  • #12696

    Alexander Bautz
    Keymaster

    Hi,
    This is no problem to make as a custom function in DFFS, but doing this in JavaScript means it will not trigger if you use datasheet view to create these items.

    Also, using the list ID as basis for the number when using JavaScript means it cannot be properly numbered from NewForm as the ID has not been set yet. The code could be applied successfully in EditForm though.

    Is the only purpose to properly sort the items ascending or descending in a list view, or do you plan to use the number as an ID for the items?

    Alexander

    • #12717

      avala
      Participant

      Thanks for looking into this.

      We’re not worried about the datasheet view as we would direct users to the Newform directly.

      We don’t have a need to reference the SP ID specifically, but if we needed to we could redirect from the NewForm to the EditForm.

      The purpose of this feautre is twofold. One, sequence a form request in sequence without numerical gaps. The SP ID creates gaps when items are created during testing, maintenance, etc. Secondly, we need to sort the list without SharePoint’s quirky numbering system in a list view.

      • This reply was modified 1 year ago by  avala.
  • #12755

    Alexander Bautz
    Keymaster

    If you only need a number to sort the list items by, you can create a single line of text field in your list, and use this code to fill it (in Custom JS):

    setFieldValue("The_Name_Of_Your_Column",new Date().valueOf());

    If you want a running number, you can use something like this to read the ItemCount from the list schema:

    function getItemCount(a){
    	if(a === undefined){
    		a = _spPageContextInfo.pageListId;
    	}
    	var b = [], iCount = "-1";
    	b.push('<GetList xmlns="http://schemas.microsoft.com/sharepoint/soap/">');
    	b.push('<listName>'+a+'</listName>');
    	b.push('</GetList>');		
    	spjs.utility.wrapSoap(_spPageContextInfo.webServerRelativeUrl + '/_vti_bin/lists.asmx', 'http://schemas.microsoft.com/sharepoint/soap/GetList', b.join(''), function(data){
    		iCount = Number(jQuery(data).find("List").attr("ItemCount"));
    	},function(err){
    		//console.log(err);
    	});
    	return iCount;
    }
    
    function dffs_PreSaveAction(){
        var currItemCount = getItemCount();
        var nextNum = currItemCount + 1;
        setFieldValue("RunningNumber",nextNum);
    }

    Put the code in the custom js and change the field “RunningNumber” to your field.

    You can call the “getItemCount” function with a list GUID or display name, but if you omit this parameter the current list is used.

    I’m not sure how this will behave with heavy load on the list – the ItemCount property might have a delayed update, but I’m not sure if this is the case.

    Please note that this will only take the total number of items in the list. If you add a list item that gets the number 100, and then go to delete one previous item form the list, the next item added will get a duplicate value of 100 as the total number of items in the list is still 100.

    Hope you can use this code example.

    Best regards,
    Alexander

You must be logged in to reply to this topic.