Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

I have been to Jan Tiernans blog, and figured out how to grab column names using Soap and jquery/jscript. I can't figure out how to grab custom columns with special chars though.

I have read about obtaining the internal field names (ie:DB%5fx0020%5fType for a column named 'DB Type'). However, when I use these in code, it does nothing.

I have no access to sharepoint designer, I am doing all of this out of a CEWP. This is what I have (which works wonderfully for any one word column ie - Title and ID):

<script type="text/javascript" src="path to..javascript/Scripts/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="path to..javascript/Scripts/jquery.listmenu-1.1.js"></script>

<script type="text/javascript">
    $(document).ready(function() {
        var soapEnv =
            "<soapenv:Envelope xmlns:soapenv='http://schemas.xmlsoap.org/soap/envelope/'> \
                <soapenv:Body> \
                     <GetListItems xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                        <listName>supported_applications</listName> \
                        <viewFields> \
                            <ViewFields> \
                               <FieldRef Name='Title' /> \
                               <FieldRef Name='ID' /> \
                           </ViewFields> \
                        </viewFields> \
                    </GetListItems> \
                </soapenv:Body> \
            </soapenv:Envelope>";

        $.ajax({
            url: "path to.../_vti_bin/lists.asmx",
            type: "POST",
            dataType: "xml",
            data: soapEnv,
            complete: processResult,
            contentType: "text/xml; charset=\"utf-8\""
        });
    });

    function processResult(xData, status) {
        $(xData.responseXML).find("z\\:row").each(function() {
              // var liHtml = $(this).attr('ows_ID') +":   " +$(this).attr('ows_Title')+'<br>';
var liHtml = "<li><a href='path to.../Lists/applications/DispForm.aspx?ID=" + $(this).attr('ows_ID') + "'>" + $(this).attr('ows_Title') + "</a></li>";

            $("#tasksUL").append(liHtml);
        });
    //function appendAnchor(
    }
</script>

<ul id="tasksUL"/>

This all works beautifully, but once I sub an 'internal name' (which has special chars) for Title, nothing works

<FieldRef Name='ID' /> \
   ...
var liHtml = "<li><a href='path to.../Lists/applications/DispForm.aspx?ID=" + $(this).attr('ows_ID') + "'>" + $(this).attr('ows_Title') + "</a></li>";

becomes

 <FieldRef Name='DB%5fx0020%5fType' /> \
    ...
 var liHtml = "<li><a href='path to.../Lists/applications/DispForm.aspx?ID=" + $(this).attr('ows_ID') + "'>" + $(this).attr('ows_DB%5fx0020%5fType') + "</a></li>";

I believe from what I have read I must use the prefix 'ows' when reffering to these column names, however I have tried all sorts of different combos of names, nothing doing. What the heck am I doing wrong?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

Why don't you use SPServices which does a very nice job for you? To get the "usual" attribute you can "unescape" in javascript:

unescape("ows_DB%5fx0020%5fType")

will be: "ows_DB_x0020_Type"

just an example of your code converted to SPServices:

$().SPServices({
    operation: "GetListItems",
    async: true,
    listName: "supported_applications",
    CAMLViewFields: "<ViewFields><FieldRef Name='ID' /><FieldRef Name='Title' /></ViewFields>",
    completefunc: function (xData, Status) {
        $(xData.responseXML).SPFilterNode("z:row").each(function() {
      var liHtml = "<li><a href='path to.../Lists/applications/DispForm.aspx?ID="
          +$(this).attr('ows_ID') + "'>" + $(this).attr('ows_Title') + "</a></li>";
            $("#tasksUL").append(liHtml);      
        });
    }
});
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.