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

Getting multiple columns in one SPGetStaticFromDisplay call

Feb 26, 2012 at 11:03 PM
Hi there, Is it possible to get multiple columns returned in a single SPGetStaticFromDisplay call? For instance, the example on your site has a single variable thisStaticName returned from a single call: var thisStaticName = $().SPServices.SPGetStaticFromDisplay ({ webURL: "", listName: "", columnDisplayName: "" }); I want to do something like: var thisStaticNames = $().SPServices.SPGetStaticFromDisplay ({ webURL: "", listName: "", columnDisplayNames: "['Title','State']" }); Thanks Joel
Feb 26, 2012 at 11:45 PM


Not as the function is currently written, but that would be a good enhancement. I'll copy this to a work item for the next release.


Feb 26, 2012 at 11:47 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Jun 17, 2012 at 5:41 AM

Added multi-column capability to both SPGetStaticFromDisplay and SPGetDisplayFromStatic in v0.7.2ALPHA5

As suggested, the syntax is:

$().SPServices.SPGetStaticFromDisplay ({
  webURL: "/",
  listName: "My List Name",
  columnDisplayNames: ['Title', 'State']


Sep 10, 2012 at 1:01 PM

Hi Marc

I've been testing this new method in the v0.7.2ALPHA5 release and it's just rocking. Thanks a lot for this.

In the last week I've been using it to replace a display form which was accidentally deleted  by a user from a DispForm.aspx page and the IT department was giving the business area no love to fix it. It works on any list.

Some of the characters, date, name columns need some cleanup in the display but I thought I'd give you a heads up to show you how I'm using it anyway.

To try it out just create a List, delete the form from the DispForm.aspx page (oops!) and then add the code in a new CEWP (with the right jquery and spservices file references of course!) .

Thanks again.


    <div id="tasksUL" width="100%"></div>

    <script type="text/javascript" src="jQuery1.7.2-min.js">
    <script type="text/javascript" src="SPServices-0.7.1a-min.js">

    <script type="text/javascript">
//Nominate some columns to filter out of display

var listOfUnwantedDisplayNames = ["Property Bag", "LinkTitle", "Approval Status","Level", "owshiddenversion", "Unique Id", "Name", "URL Path", "Attachments"];

//Get the ID number from the query string
var queryStringVals = $().SPServices.SPGetQueryString();
var lastID = queryStringVals["ID"];

//get the List Name (internal name) from the url
var thisList = $().SPServices.SPListNameFromUrl();
////get the List Name (display name) from the url

var thisListName = location.pathname.split("/");
var listStringPos = jQuery.inArray("Lists",thisListName) + 1;
var listNameURLString = thisListName[listStringPos];
//get the site URL from the query string
var thisSite = $().SPServices.SPGetCurrentSite();
//get the current query string
var currentQueryString = encodeURIComponent(location.href);

//build up the URL for the edit form
var editFormURL = thisSite + "/Lists/" + listNameURLString + "/EditForm.aspx?ID=" + lastID + "&Source=" + currentQueryString;

var editFormHTML = "<table class='ms-toolbar'><tr><td class='ms-toolbar'><a class='ms-toolbar' href=" + editFormURL + 
    "&Source=" + currentQueryString + ">Edit Item</a><\/td>&nbsp;<td><\/td><\/tr><\/table>";


    <script type="text/javascript">

    var attachmentsText = "";
    var liHtml = "";
    var camlQ = "<Query><Where><Eq><FieldRef Name='ID'/><Value Type='Text'>" + lastID + "</Value></Eq></Where></Query>";
	operation: "GetListItems",
        webURL: thisSite,
	listName: thisList,
        CAMLQuery: camlQ,
	async: false,   

        completefunc: function (xData, Status) {
            //array to build up the attachments html
            var attachmentTextHTML = [];
            $(xData.responseXML).SPFilterNode("z:row").each(function() {
                //check the attachments flag
                var intAttachments = parseInt( $(this).attr("ows_Attachments"));
                //if there are attachments
                if(intAttachments > 0){
                        operation: "GetAttachmentCollection",
                        async: false,
                        webURL: thisSite,
                        listName: thisList,
                        ID : lastID,
                        completefunc: function (xData, Status) {
                            var attachmentText = "";
                            attachmentTextHTML.push("<tr><td class='ms-formlabel'>Attachments<\/td><td class='ms-formbody'>");
                                var attachmentText = $(this).text();
                                var attachmentTextFileName = attachmentText.slice(attachmentText.lastIndexOf("/") + 1);
                                attachmentTextHTML.push("<li>" + "<a href='" + encodeURI(attachmentText) +
                                    "'>" + attachmentTextFileName + "<\/a><\/li>");
                            attachmentTextHTML = attachmentTextHTML.join("");
                //now create an array to hold the z:row attributes
                var arr = [];
                var elem = this;
                var attrs = elem.attributes;
                var colNames = [];
                var attrName = "";
                //loop through the attributes to get the internal col names
                for(var i=0, len = attrs.length; i < len; i++){
                    attrName = attrs.item(i).nodeName;
                    attrName = attrName.substring(4);
                //now get the display names from the internal names
                thisDisplayNames = $().SPServices.SPGetDisplayFromStatic({	
                    webURL: thisSite,
                    listName: thisList,
                    columnStaticNames: colNames
                //get rid of useless columns
                for(var m in thisDisplayNames ){
                    var isInArray = jQuery.inArray(thisDisplayNames[m],listOfUnwantedDisplayNames);
                    if(isInArray !== -1){
                        delete thisDisplayNames[m];
                //build up some html for the columns and their values
                for(var j=0, leng = attrs.length; j < leng; j++){
                    attrName = attrs.item(j).nodeName;
                    attrName = attrName.substring(4);
                        arr.push("<tr id='" + attrName + "'><td class='ms-formlabel'>" + thisDisplayNames[attrName] + 
                            "<\/td><td class='ms-formbody'>" + attrs.item(j).nodeValue + "<\/td/><\/tr>");
                //turn the html values into a string
                var tableHTML = arr.join("");
                //append to the div
                //add the edit button