The Stack Overflow podcast is back! Listen to an interview with our new CEO.

Hot answers tagged

14

Thanks for the answer: i tried no luck. This one worked for me: $.ajax({ url: Url, method: 'GET', beforeSend: function (XMLHttpRequest) { XMLHttpRequest.setRequestHeader("Accept", "application/json; odata=verbose"); }, cache: true, error: function (data) { ////failure ...


13

You can't update field values in the same call that uploads the document, you have to do that in a separate call. The response from the call that uploads the document will be a SP.File object representing the file that was just created. This object will have a deffered property called ListItemAllFields, which you can use to get the URL needed to make a call ...


13

SP Foundation does not include the User Profile Service, as @Aveenav noted. Therefore you probably do not have access to the REST endpoints for that service. Instead you will have to use the user information list to get this information. This will require two requets: one to get the current user's id, the second to get the user's info that you want. ...


12

The ItemCount function could be applied to List resource, for example: /_api/web/lists/getbytitle('<list title>')/ItemCount but not to ListItemCollection resource You could consider the following options of getting items count for list items: Option 1 How to return items count from json result: var endpointUrl = _spPageContextInfo....


11

I can't see any reason to prevent the uploading of JSON files, this file format is as harmless as XML since it only stores data, not executable code. In comparison, uploading a HTML file would be much more dangerous since it's possible to place some malicious JavaScript code on it that steals cookies from users that access it, for example. As a possible ...


7

<script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> <script> function restEndPoints2013(){ $.ajax({ url: "http://site/_api/Web/Lists/GetByTitle('listName')/items(3)", type: "GET", headers: {"accept": "application/json;odata=verbose"}, success: function(data){ ...


7

How to copy List Item using SharePoint 2013 REST function getListItem(webUrl, listName,listItemId, complete, failure) { $.ajax({ url: webUrl + "/_api/web/lists/getbytitle('" + listName + "')/items(" + listItemId + ")", method: "GET", headers: { "Accept": "application/json; odata=verbose" }, success: function (data) { ...


6

Well, I am not absolutely sure, but I think the answer is: there is no way to skip metadata property. You may of course create a kind of proxy by implementing a custom web service which itself consumes listdata.svc and truncates the __metadata property? But it doesn't sound good to me. You can of course skip all other unnecessary properties by defining the ...


5

If you want JSON you should use the REST API instead of the Client Object Model. var call = jQuery.ajax({ url: _spPageContextInfo.webAbsoluteUrl + "/_api/Web/Lists/getByTitle('CountriesLimits')", type: "GET", dataType: "json", headers: { Accept: "application/json;odata=verbose" } }); call.done(function (data, textStatus, jqXHR) {...


5

1) Get all properties of current user: http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties 2) Get single property of current user: http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties/PictureUrl OR http://siteurl/_api/SP.UserProfiles.PeopleManager/GetMyProperties?$select=PictureUrl 3) Get Multiple Properties for the current ...


5

When you query /_api/web/Lists/getbytitle(\'Items\') basically it returns SPList object. That object as ItemCount property. The value of the ItemCount property includes folders within a list/document library, as well as items/files within subfolders. For filtering we need to apply filter on Items so query /_api/web/Lists/getbytitle(\'Items\')/items?$filter=...


5

It probably fails because you haven't set itemEntry.MMField = {}; Try using object literal notation (note __metadata): itemEntry.MMField = { __metadata: { type: "SP.Taxonomy.TaxonomyFieldValue" }, Label: '7', TermGuid: "7d5e44d8-e5a7-4eb7-9735-7b51cea64aa8", WssId: -1 }; Update: An alternative solution is to set HTTP request header Content-...


5

It seems that your default view is created using datasheet mode, try to create a view using standard template and then set it as default view. It will no longer open in quick edit mode.


4

you need to place quotes around the url and a semicolon: var stringURL = "http://mydomain.com/Sandbox/bitest/_vti_bin/ListData.svc/Produce";


4

You can perform a REST request, and have the results returned in a JSON object: $.ajax({ url: "http://site url/_api/web/lists/GetByTitle('Test')/items", type: "GET", headers: { accept: "application/json;odata=verbose", content-type: "application/json;odata=verbose" }, success: function(data) { // you can find the ...


4

It appears that the list resides in Host web instead of the App web. In this case the app needs to be given permission to read the List of the host web. Moreover, the REST call needs to be done using cross domain library. Example of cross domain call using REST: executor.executeAsync( { url: appweburl + "/_api/SP....


4

I think I got it. The ACCEPT header parameter "odata = verbose" makes all the difference. Using it returns the "d/results" path. Not using it returns "value" path. I understand that there is no need to add it any more with new specs. Further details here: https://blogs.office.com/2014/08/13/json-light-support-rest-sharepoint-api-released/ Edit: Also I ...


4

The ID is an object property, so you need to access it like an object property using the square bracket notation instead of dot notation: var array = ["ID", "Title"]; data.d.results[i][array[0]]; Using the bracket notation, JS will translate [array[0]] into [ID] which is equal to .ID (notice the dot). Using the dot notation, JS expects array[0] to be an ...


4

I've also come across this issue, and although I don't claim any particular expertise, it appears that you need to have the referenced field available to the selected view. Paul CJ


4

It seems that you are not sending the same Accept header in all GET requests. You can set Accept header to: application/json (your second response) application/json;odata=nometadata application/json;odata=verbose (your first response)


3

What I have working is the following: Method POST URL http://www.somewhere.com/testsite/_api/web/GetFolderByServerRelativeUrl('/testsite/Shared Documents')/Files/add(url='filename.png',overwrite=true) Header Content-Type: application/octet-stream Accept: application/json;odata=verbose X-RequestDigest: ... Body Raw binary bytes (no JSON) Then in the ...


3

Your question implies that you already know the specific item. That makes it easier to isolate the data you want. Each of the lines shown will return a text response as shown below assuming that these are not "special" fields like choice, lookup, etc. This URL will return christophe http:/.../_vti_bin/listdata.svc/Contacts(2988)/Contact/$value This URL ...


3

Yes, you can use web services from within SharePoint. Since you are in this case using jQuery and will likely go from one domain (URL) to another (that is cross domain), you cannot use JSON as it is, but instead have to rely on JSONP. I've written an example of usage in a post, where the SharePoint site is hosted in Office 365/SharePoint Online and the ...


3

Iterate through data.d.results: function(data) { $.each(data.d.results, function(i,result) { //get item property var strTitle = result.Title; });


3

It's not a good idea to disable the handler. In SharePoint 2013, some services like Managed Metada or Excel Services are relying on it and won't work anymore without it. For example, when you open an Excel file in SharePoint using Excel services, the page calls some .json files when loading : [myserver]/_vti_bin/DynamicGridContent.json/GetRangeContent Or ...


3

Have a look at http://blog.jsonpify.com/ or, as suggested on the blog above, have a look at http://developer.yahoo.com/yql/ YQL can be called from client script using JSONP, allowing you to pass a SQL-ish query against an "Open Data Table". An Open Data Table is an abstraction layer similar to a BCS model in SharePoint. An Open Data Table abstracts web ...


3

Hmm %7B%0A%09%22d%22%3A%0A%09%7B%0A%09%09%22__metadata%22%3A%0A%09%09%7B%0A%09%09%09%22type%22%3A+%22SP.Data.DocLibItem%22%0A%09%09%7D%2C%0A%09%09%22Title%22%3A+%22This+is+my+testtitle%22%0A%09%7D%0A%7D%0A Decodes as a proper odata result { "d": { "__metadata": { "type": "SP.Data.DocLibItem" }, "Title": "...


3

This seems like it's as much a JS question as it is a SharePoint question: Step 1 is get the results Step 2 is process the results yourself to make an object that looks like you want Example (assuming you're using jQuery): // Step 1: Get the results $.getJSON("/_api/web/siteusers", function(data) { //remove these console.log statements before using ...


3

In SharePoint 2013 you can't use Content Editor Webpart for embedding JavaScript. Instead you should move it to Script Editor Webpart. Another option is to store the HTML and Script in a file. And then reference that file in the Content Editor webpart using the Content Link property.


Only top voted, non community-wiki answers of a minimum length are eligible