Showing posts from March, 2017

Creating Services with SPFx

Update 21st April 2017: While the SPFx service model behaves as expected on the SharePoint workbench, I've had less success when the web parts that consume the service are packaged and deployed via the App Catalog. When the script files and the service package are served locally, the service class is instantiated only once. When the script files are served from a CDN, the service class is instantiated multiple times: once by each web part that consumes the service. The call to ServiceKey.create is also executed once for each web part that consumes the service - which effectively means that the page-level ServiceScope hosts multiple instances of the same service, each registered against a different ServiceKey object. I can only assume that this is due to a nuance of the bundling process that I'm missing.  The result of this is that the SPFx service model isn't currently all that useful to me for sharing data between web parts. As a workaround, I've reverted to storing da

SharePoint Framework POST requests: watch out for OData version incompatibility

This week I've been building a SharePoint Framework web part that queries a Pages list, amongst other things. For reasons that I won't go into, I need to do this by sending a CAML query to the server. The usual way to do this is to send a POST request to the getitems REST endpoint: [Web URL]/_api/web/lists/getbyid('[List GUID]')/getitems Where the body of the request contains your CAML query: 'query': {    '__metadata': {'type': 'SP.CamlQuery' },    'ViewXml': '<View><Query><Where>...' } To do this the SPFx way, we leave jQuery.ajax behind and use the method. However, when I did this, the server returned an HTTP 400/Bad Request response with the error message: The property '__metadata' does not exist on type 'SP.CamlQuery'. Make sure to only use property names that are defined by the type. After a bit of trial and error in Fiddler, I found the problem: