1

right now this code writes out the subsites title and relativeurl, but it also includes my title of my app, but i only want to display the subsites title and not title of the app also,

Any sugesstions what i should do? Here is my code

 function execCrossDomainRequest() { var executor = new SP.RequestExecutor(appweburl); var queryUrl = appweburl + "/_api/SP.AppContextSite(@target)/web/webs?$select=Title,ServerRelativeUrl&@target='" +hostweburl + "'" ; executor.executeAsync( { url: queryUrl, method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: successHandler, error: errorHandler } ); } }) function successHandler(data) { $("#subSiteTitle").keypress(function () { var jsonObject = JSON.parse(data.body); var dataArr = $.makeArray(jsonObject.d.results); var resultArr = $.map(dataArr, function (item) { return { label: item.Title + " (" + item.ServerRelativeUrl + ")", value: item.ServerRelativeUrl }; }); 

1 Answer 1

1

The app hosted in SharePoint creates a sub site under the Host Site. This sub site is called App Web and it has the same name as that of the app. A filter needs to be added to the REST query so that this app web is the not included in the result set. Suppose the name of the app web is "App1", the filter will look like this:

$filter= Title ne 'App1' 

In your case the REST Url will be:

var queryUrl = appweburl + "/_api/SP.AppContextSite(@target)/web/webs?$select=Title,ServerRelativeUrl&$filter= Title ne 'NameOFApp'&@target='" +hostweburl + "'" ; 

Replace 'NameOFApp' with name of your app.

UPDATE

Since you can have 'n' number of Apps in a Host site and obviously hard coding name of the app in filter is not an option. The other way to not include app webs in result set is to use WebTemplate in the filter. The filter to exclude App webs is:

$filter=WebTemplate ne 'APP' 
6
  • Alright but if i dont not the name of the app, because when i have 2 apps its displays 2 titles. so if the user adds more apps it will be displayed? Commented Jan 12, 2015 at 6:45
  • Sorry, I did not get you. Can you elaborate. Commented Jan 12, 2015 at 6:51
  • I have two apps, and 2 subsites, all four are displayed. when using $filter= Title ne i must now the the name of the app as u have replayed. But if the user and 1 more app so its 3 apps and 2 subsites how should my filter know the name of the app? when i hard code what the name is? Commented Jan 12, 2015 at 6:54
  • See the updated answer. Commented Jan 12, 2015 at 7:08
  • alright i dont got it to work i get bad request when using $filter=WebTemplate ne 'AppWeb' Commented Jan 12, 2015 at 7:12

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.