This project has moved and is read-only. For the latest updates, please go here.

Referencing and Modifying ListID in Edit Form

Jan 13, 2014 at 8:12 PM
Hi there,

I have a simple script that I am using locally to generate unique Project IDs for numerous projects throughout our department. I want to move this script into SharePoint (specifically adding it into a custom list Edit form). The schema for the project IDs is as follows:

Prefix + Leading Zeros + ProjectID.... so in SharePoint I would be looking for the format to be a concatenated value (PROJ,LeadingZeros,ListItemID). Essentially I have the PROJ prefix and then a five digit number with a variable amount of zeros based on the number of characters in the ID.

My script looks like this:
var fillZeroes = "00000"; // max number of zero fill ever asked for in global

function zeroFill(number, width) {
    // make sure it's a string
    var input = number + "";
    var prefix = "PROJ";
    if (input.charAt(0) === '-') {
        prefix = "-";
        input = input.slice(1);
    var fillAmt = Math.max(width - input.length, 0);
    return prefix + fillZeroes.slice(0, fillAmt) + input;
var testValue = "3";
var result;
for (var i = 0; i < testValue.length; i++) {
    result = zeroFill(testValue[i], 5);
    document.getElementById("projID").innerHTML = result;

I am hoping to use SPservices to pull in the current items ID and incorporate it into the script I have above (i.e. - setting the variable "testValue" to the list Item's ID) and then posting this string to an empty single-line text field.

Any ideas on how I may be able to accomplish this? I am experiencing issues referencing the item's ID. Any help would be greatly appreciated. Thanks!!
Jan 17, 2014 at 12:53 PM
You haven't indicated what page you're trying to do this from so I'll give you a couple suggestions. If you are in the EditForm.aspx of the record, the ID is an easy extraction from the URL query parameters. First, extract the query parameters as an array, then grab the parameter you want as follows:
//Get the query string as an array
var qs = $().SPServices.SPGetQueryString();
//Set lngRcdID as the ID parameter from the array
var lngRcdID = qs.ID;
If you are trying to capture this from NewForm.aspx, the record ID doesn't exist yet. However, you can still capture it after the fact using the $().SPServices.SPRedirectWithID function (runs as you save a new record). That will allow you to redirect to a page of your choice and will include the new record's ID in the URL querystring. In the new page you are redirecting to, you can run an UpdateListItems function to update the field on the new record. This method is a bit more cumbsome, of course, but it works.