0

I am new to SharePoint and for this project I need to add new filter to the CAML query, but I have no idea what field names are available.

Is there anyway I can know what FiledRef name I should use in the CAML query, please? I try to figure out what FieldRefName I should put into the query below:

<FieldRef Name='FieldRefName' /> <Value Type='TaxonimyFieldType'>value</Value>

Any suggestion? Thanks in advance.

UPDATE: This is to filter a list of contents in SharePoint using those columns used in each content page. e.g. by Industry, Sector, etc.

0

One way to do it a field at a time is to go to List Settings and click on one of your column names. You'll find the internal name on the URL.

URL with internal field name

I do this so much I created a wiki page with the following code - I enter the site name, select the list, and it gives me a formatted display of all the fields. I grabbed this years ago off of a site somewhere when we were still on SharePoint 2007 - I'd probably code it differently now but this works. You'll need to add a reference to JQuery.

        <h1>Display List Field Names</h1>
        Enter site:<br />
        <input type="text" name="fmgSiteName" id="fmgSiteName"/>
        <input type="button" class="ms-ButtonHeightWidth" value="Find Lists" onclick="javascript:retrieveLists(fmgSiteName.value)"/>
        <br />
         <select id="spLists" onchange="displayFieldData(this.options[this.selectedIndex].value)"><option>
            Enter site starting with / above...</option></select>
        <div id="spListsSelected"></div>
        <table id="spListFieldTable" cellpadding="0" cellspacing="0" style="width: auto"></table>

     <script type="text/javascript">
       var siteURL;
        var arrSkipFieldTypesOf = ['Computed'];
        var arrIncludeOverrideFields = ['Title','Author','Created','Modified','Editor'];

 function retrieveLists(siteName) {
            siteURL = window.location.protocol + "//" + window.location.host + siteName + '/_vti_bin/lists.asmx';
            var soapEnv = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
                            <soap:Body> \
                            <GetListCollection xmlns='http://schemas.microsoft.com/sharepoint/soap/' /> \
                            </soap:Body> \
                            </soap:Envelope>";
            $.ajax({
                url: siteURL,beforeSend: function(xhr) {
                    xhr.setRequestHeader("SOAPAction",
                    "http://schemas.microsoft.com/sharepoint/soap/GetListCollection");
                },
                type: "POST",
                async: false,
                dataType: "xml",
                data: soapEnv,
                complete: processResult,
                contentType: "text/xml; charset=\"utf-8\""
            });

        }

        function processResult(xData, status) {
            $("#spLists").empty();
            $("#spLists").append("<option>Select a List</option>");
            $(xData.responseXML).find("List").each(function() {
            var liHtml = "<option value='" + $(this).attr("Title") + "'>" + $(this).attr("Title") + "</option>";
            $("#spLists").append(liHtml);
            });
        }

        function displayFieldData(listname) {
            if(listname == "" || listname == undefined) return false;
            var soapEnv = "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'> \
                            <soap:Body> \
                            <GetList xmlns='http://schemas.microsoft.com/sharepoint/soap/'> \
                            <listName>" + listname + "</listName> \
                            </GetList> \
                            </soap:Body> \
                            </soap:Envelope>";
            $.ajax({
                url: siteURL,
                beforeSend: function(xhr) {
                xhr.setRequestHeader("SOAPAction",
                "http://schemas.microsoft.com/sharepoint/soap/GetList");
                },
                type: "POST",
                async: false,
                dataType: "xml",
                data: soapEnv,
                complete: processResult2,
                contentType: "text/xml; charset=\"utf-8\""
            });
        }

        function processResult2(xData, status) {
            $("#spListFieldTable tr").remove();
            $("#spListFieldTable").append("<tr style='font-weight:bold;'><td style='padding-right:10px'>DisplayName</td><td style='padding-right:10px'>FieldInternalName</td><td style='padding-right:10px'>FieldType</td></tr>");
            $(xData.responseXML).find("Field").each(function() {
                if (($.inArray($(this).attr('Name'),arrIncludeOverrideFields)>-1) || ($(this).attr('FromBaseType')!='TRUE' && $(this).attr('Sealed')!='TRUE' && $(this).attr('DisplayName')!=undefined && $.inArray($(this).attr('Type'),arrSkipFieldTypesOf)==-1)) {
                    var trHtml = "<tr>";
                    trHtml += "<td style='padding-right:10px'>" + $(this).attr("DisplayName") + "</td>";
                    trHtml += "<td style='padding-right:10px'>" + $(this).attr("Name") + "</td>";
                    trHtml += "<td style='padding-right:10px'>" + $(this).attr("Type") + "</td>";
                    trHtml += "</tr>";
                    $("#spListFieldTable").append(trHtml);
                }
            });
            $("#spListFieldTable tr:odd").css("background-color","rgb(206,206,206)");
        }
    </script>
  • You mean something like a sorting action? – Xiao Han Oct 24 '17 at 20:32
  • I answered before your update - I was more talking about what the fields are in a list/library, not how to determine what is in a taxonomy classification. So this answer won't help - we don't use managed data fields. Sorry 'bout that. – Robin in Or Oct 24 '17 at 20:59
  • Sorry, I didn't ask clearly. Any idea how to find out the field name when use managed data fields? Is that something I need to check somewhere from the data source or SharePoint might store it somewhere? – Xiao Han Oct 25 '17 at 1:24
  • Not in detail. We don't use managed data fields. I just did a test, added one field and see it added 2 field entries - one called TestMD of type 'TaxonomyFieldType', and one called TestMD_0 with a guid-like name for an internal name of type Note. It showed up in the display of the list from my code above. Don't know how to get at the actual values of the managed data though. – Robin in Or Oct 25 '17 at 15:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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