locked
Unable to write to BCS (external data, from WCF service) List on root site collection from SharePoint App using the JSOM or jQuery. RRS feed

  • Question

  • The root issue here is that we have an App on the app domain that needs to be able to write to an External Data List on the root site collection. The JSOM code is firing and the success callback function is running and returning with the following information (see end of post), where it reports "success!". The weird thing is that all of the reported URIs are not only wrong, but the CORRECT URI is being used in the call.

    But the information is not being written to the list.

    Architecture:

    The External Data list is coming from a WCF application hosted on IIS. The WCF application is reading/writing to a single table in MS SQL Server 2012. The WCF service is working as it is usable from the WCF Test Clientn, the data is viewable by going directly to the list in SharePoint and adding a new item through the SP UI works. BCS is configured to use a specific AD account that has permission to use the WCF services and SQL server.

    The External Data list is set up on the root site collection (http://sp2013dev/Lists/MyWCFList) and the App is running in the App Web which is a separate domain (http://spdevapps.local).

    Noteworthy Items:

    • The App is able to make calls to regular SharePoint lists using the same code and CRUD operations are working without an issue.
    • Using CORS I am able to make jsonp calls to the root site collection with jQuery. jQuery REST calls are not working either. In this case neither the success nor the failure callbacks run
    • The main way we are working with SP data is via the Cross-Domain Library. In this instance the Success callback is running, but the data is NOT written to the external data list
    • The way we are doing Apps is a little unorthodox in this situation because we have have a suite of custom apps that are sharing data (including logging) on the root site collection. Normally all of the content types, etc would be contained for an app, but in this case there is little native to the Apps. All lists, and most JavaScript reside at the root site collection. The Apps all have Full Control rights to the Site Collection in the AppManifest. External Data lists are the only lists we are having an issue with.

    Is there a special set of permissions or a special case of how the external data lists/content types need to be set up? 

    Here is the code that is doing the write to the list (again, this is working for many lists across several apps, so I know it works for regular SP lists, at least)

    var addItemToList = function (listName, successCallback, errorCallback, jsonRequest) {
                var url = _appWebUrl + "/_api/SP.AppContextSite(@target)/web/lists/getByTitle('" + listName + "')/items?@target='" + _hostWebUrl + "'";
    
                _executor.executeAsync({
                    url: url,
                    method: "POST",
                    headers: {
                        "accept": "application/json;odata=verbose",
                        "content-type": "application/json;odata=verbose",
                        "X-RequestDigest": $("#__REQUESTDIGEST").val(),
                    },
                    body: JSON.stringify(jsonRequest),
                    success: successCallback,
                    error: errorCallback
                });
            }

    the success callback is simple : function(data) { console.log(data); }
    Here is the contents of the "data" argument

    {
    	"responseAvailable" : true,
    	"body" : "{\"d\":{\"__metadata\":{\"id\":\"f53a1058-804c-474a-bf84-2afaa3021563\",\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(guid'b1fe39bf-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)\",\"type\":\"SP.Data.MyWCFListItem\"},\"FirstUniqueAncestorSecurableObject\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(gu…279ee3d98e4f')/GetItemByStringId(null)/FirstUniqueAncestorSecurableObject\"}},\"RoleAssignments\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(gu…9bf-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/RoleAssignments\"}},\"AttachmentFiles\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(gu…9bf-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/AttachmentFiles\"}},\"ContentType\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(gu…1fe39bf-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/ContentType\"}},\"FieldValuesAsHtml\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(gu…f-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/FieldValuesAsHtml\"}},\"FieldValuesAsText\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(gu…f-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/FieldValuesAsText\"}},\"FieldValuesForEdit\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(gu…-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/FieldValuesForEdit\"}},\"File\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(guid'b1fe39bf-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/File\"}},\"Folder\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(guid'b1fe39bf-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/Folder\"}},\"ParentList\":{\"__deferred\":{\"uri\":\"http://app-a5068cfc996a84.spdevapps.local/MyApp/_api/Web/Lists(gu…b1fe39bf-b959-405a-87f5-279ee3d98e4f')/GetItemByStringId(null)/ParentList\"}},\"FileSystemObjectType\":0,\"Id\":0,\"BdcIdentity\":null,\"CurrentUser\":null,\"exception\":null,\"level\":null,\"Logger\":null,\"message\":null,\"thread\":null,\"Timestamp\":null}}",
    	"statusCode" : 201,
    	"statusText" : "Created",
    	"contentType" : "application/json;odata=verbose;charset=utf-8",
    	"allResponseHeaders" : "Date: Tue, 26 Nov 2013 20:46:37 GMT\r\nX-Content-Type-Options: nosniff\r\nX-AspNet-Version: 4.0.30319\r\nX-Powered-By: ASP.NET\r\nTransfer-Encoding: chunked\r\nX-SharePointHealthScore: 0\r\nrequest-id: 6b855a9c-64ce-c026-d06f-b2d43b8653a2\r\nMicrosoftSharePointTeamServices: 15.0.0.4420\r\nX-MS-InvokeApp: 1; RequireReadOnly\r\nLast-Modified: Tue, 26 Nov 2013 20:46:37 GMT\r\nServer: Microsoft-IIS/8.0\r\nSPRequestGuid: 6b855a9c-64ce-c026-d06f-b2d43b8653a2\r\nX-FRAME-OPTIONS: SAMEORIGIN\r\nContent-Type: application/json;odata=verbose;charset=utf-8\r\nAccess-Control-Allow-Origin: *\r\nCache-Control: private, max-age=0\r\nSPClientServiceRequestDuration: 154\r\nX-RequestDigest: 0x9FE985604DB14A76563BBFD6FA1391C9BC8938DDC41BCBAFF883D4ABE4474B92546DA30DBF8403E884CEACEE137AE38269534DC65BAFA8C637C37EF68F666E2A,26 Nov 2013 20:46:37 -0000\r\nExpires: Mon, 11 Nov 2013 20:46:37 GMT\r\n",
    	"headers" : {
    		"DATE" : "Tue, 26 Nov 2013 20:46:37 GMT",
    		"X-CONTENT-TYPE-OPTIONS" : "nosniff",
    		"X-ASPNET-VERSION" : "4.0.30319",
    		"X-POWERED-BY" : "ASP.NET",
    		"TRANSFER-ENCODING" : "chunked",
    		"X-SHAREPOINTHEALTHSCORE" : "0",
    		"REQUEST-ID" : "6b855a9c-64ce-c026-d06f-b2d43b8653a2",
    		"MICROSOFTSHAREPOINTTEAMSERVICES" : "15.0.0.4420",
    		"X-MS-INVOKEAPP" : "1; RequireReadOnly",
    		"LAST-MODIFIED" : "Tue, 26 Nov 2013 20:46:37 GMT",
    		"SERVER" : "Microsoft-IIS/8.0",
    		"SPREQUESTGUID" : "6b855a9c-64ce-c026-d06f-b2d43b8653a2",
    		"X-FRAME-OPTIONS" : "SAMEORIGIN",
    		"CONTENT-TYPE" : "application/json;odata=verbose;charset=utf-8",
    		"ACCESS-CONTROL-ALLOW-ORIGIN" : "*",
    		"CACHE-CONTROL" : "private, max-age=0",
    		"SPCLIENTSERVICEREQUESTDURATION" : "154",
    		"X-REQUESTDIGEST" : "0x9FE985604DB14A76563BBFD6FA1391C9BC8938DDC41BCBAFF883D4ABE4474B92546DA30DBF8403E884CEACEE137AE38269534DC65BAFA8C637C37EF68F666E2A,26 Nov 2013 20:46:37 -0000",
    		"EXPIRES" : "Mon, 11 Nov 2013 20:46:37 GMT"
    	}
    }

    Tuesday, November 26, 2013 8:59 PM

Answers