2

I am retrieving pages using CAML, and doing for loop on the results like the following:

 function _onSucceed(){
     var html="";                   
     for(var i = 0; i <results.length; i++){
         html+= results[i].get_item("PublishingPageImage");
     }           
 }

But what property should I use if I want to get the URL for the web page? Also how do I get a list of properties I can use for the returned type. All I can see in the developer tool is just method definitions like get_item and so on, but how do I know exact properties I can use with get_item()?

  • Have you tried Url? The list of properties depends on what all you are requesting. – Amal Hashim Jan 23 '15 at 21:06
  • 1
    You can use Fiddler (telerik.com/fiddler) to see the properties returned by the query and so available in get_item(). – pholpar Jan 23 '15 at 21:28
  • Thanks @pholpar , do you have example on how to check these properties in fiddler? Do I just try it on get_item() without any param? Does it return all properties? Does it also return the values for these properties? Sorry I'm a bit lost. – Brittany Rutherford Jan 23 '15 at 21:46
  • You should simlpy submit your query with executeQueryAsync, no get_item() is required. Format the request as XML and the response as JSON in Fiddler, see the properties in the response. In case of a CAML query these properties should correspond with the field names requested in ViewFields. – pholpar Jan 23 '15 at 21:55
  • Thanks pholpar, but this is exactly my problem, how do I know the properties I need? for example how did Amal know there is one called: FileRef? – Brittany Rutherford Jan 24 '15 at 6:21
1

You can get the File URL using following property

function _onSucceed(){
     var html="";                   
     for(var i = 0; i <results.length; i++){
         html+= results[i].get_item("FileRef");
     }           
 }

To form the full URL you can use _spPageContextInfo.webAbsoluteUrl + results[i].get_item("FileRef")

1

When doing a CAML query for the page web URL I use:

var fieldsToRead = "<ViewFields>" + "<FieldRef Name='WebPage' />" + "</ViewFields>";

as my CAMLViewFields

var web = ($(this).attr("ows_WebPage"));

gets the URL for the page.

$("#relatedTable").append("<tr>" + "<td>" + "<a href=" + web + ">" + name + "</a>" + "</td>" + "</tr>");

That is how I display the data in a table. As with regards to learning the field names, you have to go into the relevant list on SharePoint and lookup the column to find the internal property name used by SharePoint for the relevant field.

0

FileRef will only return the relative url of the page item. For retriving the full URL of the publishing page item, ask for the fileld

EncodedAbsUrl

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.