I am having issues connecting to the Host Site of the App, to query a List and obtain information.
If i manually navigate to the url, `HostURL/_api/web/Lists/getByTitle('tblTestList')/items?$select=BdcIdentity,value', it executes and produces and expected XML result.
But when i execute a similar query using Ajax/Json, i get either Cross-Domain error response or the Log below, which results in short to Cross-Domain.
In both situations they are at least in the same SiteCollection. Both are being hosted under the same account under O365. Eventually i will be moving this to our internal SharePoint but i need to see what i can, or can not, do because clients of ours will be using this and other controls through extranet portal.
Please look at the below and let me know what you think. Whether i use the JS/Ajax API URL syntax or the JSOM syntax, i get the same result.
I just need one or the other to work. Any help would be greatful.
And if it matters the List is actually an ECT with a BCS connection. I dont need to Push/Put to the List, just need to Get from it.
AppManifest.xml:
<App xmlns="http://schemas.microsoft.com/sharepoint/2012/app/manifest"
Name="SQLTextBox"
ProductID="{158edc40-7ce4-4c5e-a7ab-2e72b3179b3b}"
Version="1.0.0.0"
SharePointMinVersion="15.0.0.0"
>
<Properties>
<Title>SQLTextBox</Title>
<StartPage>~appWebUrl/Pages/Default.aspx?{StandardTokens}</StartPage>
</Properties>
<AppPrincipal>
<Internal AllowedRemoteHostUrl="~remoteAppUrl" />
</AppPrincipal>
<AppPermissionRequests AllowAppOnlyPolicy="false">
<AppPermissionRequest Scope="http://sharepoint/social/tenant" Right="Read" />
<AppPermissionRequest Scope="http://sharepoint/bcs/connection" Right="Read" />
<AppPermissionRequest Scope="http://sharepoint/content/tenant" Right="Read" />
</AppPermissionRequests>
</App>
Default/WebApp Pages:
<%@ Page Language="C#" Inherits="Microsoft.SharePoint.WebPartPages.WebPartPage, Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="SharePoint" Namespace="Microsoft.SharePoint.WebControls" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="Utilities" Namespace="Microsoft.SharePoint.Utilities" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<%@ Register TagPrefix="WebPartPages" Namespace="Microsoft.SharePoint.WebPartPages" Assembly="Microsoft.SharePoint, Version=15.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %>
<WebPartPages:AllowFraming ID="AllowFraming" runat="server" />
<html>
<head>
<title></title>
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript" src="//ajax.aspnetcdn.com/ajax/4.0/1/MicrosoftAjax.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.runtime.js"></script>
<script type="text/javascript" src="/_layouts/15/sp.js"></script>
<script type="text/javascript" src="../Scripts/App.js"></script>
<script type="text/javascript">
'use strict';
// Set the style of the client web part page to be consistent with the host web.
(function () {
var hostUrl = '';
if (document.URL.indexOf('?') != -1) {
var params = document.URL.split('?')[1].split('&');
for (var i = 0; i < params.length; i++) {
var p = decodeURIComponent(params[i]);
if (/^SPHostUrl=/i.test(p)) {
hostUrl = p.split('=')[1];
document.write('<link rel="stylesheet" href="' + hostUrl + '/_layouts/15/defaultcss.ashx" />');
break;
}
}
}
if (hostUrl == '') {
document.write('<link rel="stylesheet" href="/_layouts/15/1033/styles/themable/corev15.css" />');
}
})();
</script>
</head>
<body>
<div>
<label id="lblWelcome">
<!-- The following content will be replaced with the user name when you run the app - see App.js -->
initializing...
</label>
<label id="sqlData">Loading Data...</label>
</div>
</body>
</html>
App.js
'use strict';
var qsParams = {}, qsHostUrl, qsAppUrl, factory, lstData;
var currContext = SP.ClientContext.get_current();
var web = currContext.get_web();
var user = web.get_currentUser();
// This code runs when the DOM is ready and creates a currContext object which is needed to use the SharePoint object model
$(document).ready(function () {
parseQueryString();
assignQueryStringVariables();
getUserName();
$.getScript(qsHostUrl + "/_layouts/15/SP.RequestExecutor.js", execCrossDomainRequest);
});
// Function to prepare and issue the request to get
// SharePoint data
function execCrossDomainRequest() {
currContext = new SP.ClientContext(qsAppUrl);
factory = new SP.ProxyWebRequestExecutorFactory(qsAppUrl);
currContext.set_webRequestExecutorFactory(factory);
var appContextSite = new SP.AppContextSite(currContext, qsHostUrl);
this.web = appContextSite.get_web();
currContext.load(this.web);
var lst = this.web.get_lists().getByTitle('tblTestList');
var caml = "<View><ViewFields" +
"<FieldRef Name='BdcIdentity' />" +
"<FieldRef Name='value' />" +
"</ViewFields></View>";
var camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(caml);
lstData = lst.getItems(camlQuery);
currContext.load(lstData, "Include(BdcIdentity,value)");
currContext.executeQueryAsync(postData, postError);
function postData(data, req) {
var outHtml = "";
var iter = lstData.getEnumerator();
outhtml = "<H2>tblTestList Data</H2><table>";
while (iter.moveNext()) {
var itm = iter.get_current();
outhtml = outhtml +
"<tr>" +
"<td>" + itm.get_item("BdcIdentity") + "</td>" +
"<td>" + itm.get_item("value") + "</td>" +
"</tr>";
}
outhtml = outhtml + "</table>";
$("sqlData").html(outhtml);
}
function postError(data, errorCode, errorMessage) {
$("#sqlData").html("<span>Could not complete cross-domain call: " + errorCode + " - " + errorMessage + "</span>");
}
}
// Parse the Query string from the URL
function parseQueryString() {
var temp, i, l; //unassigned declarations
//assignment declarations
var url = document.URL;
var qs = url.substring(url.indexOf('?') + 1);
var params = qs.split("&");
for (i = 0, l = params.length; i < l; i++) {
temp = params[i].split('=');
qsParams[temp[0]] = temp[1];
}
}
function assignQueryStringVariables() {
qsAppUrl = decodeURIComponent(qsParams["SPAppWebUrl"]);
qsHostUrl = decodeURIComponent(qsParams["SPHostUrl"]);
}
// This function prepares, loads, and then executes a SharePoint query to get the current users information
function getUserName() {
currContext.load(user);
currContext.executeQueryAsync(onGetUserNameSuccess, onGetUserNameFail);
}
// This function is executed if the above call is successful
// It replaces the contents of the 'message' element with the user name
function onGetUserNameSuccess() {
$('#lblWelcome').text('Hello ' + user.get_title());
}
// This function is executed if the above call fails
function onGetUserNameFail(sender, args) {
alert('Failed to get user name. Error:' + args.get_message());
}
Chrome Developer Log:
Mon Mar 24 2014 15:48:26 GMT-0500 (Central Daylight Time):The frame element does not exist. Put request in queue SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:26 GMT-0500 (Central Daylight Time):Created IFrame https://appdomain/SQLTextBox/_layouts/15…appdomain/SQLTextBox/Pages/Default.aspx SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:26 GMT-0500 (Central Daylight Time):Create IFrameLoadTimeout 11 SP.RequestExecutor.js?_=1395693884243:2
Resource interpreted as Image but transferred with MIME type text/css: "https://appdomain/_layouts/15/1033/styles/corev15app.css?rev=sXnpy4muBCj0VRzQDI3uMg%3D%3D". init.js?rev=VzO%2FY8hYnnXmC5pJBAUtHQ%3D%3D:1
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.Init sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.addEventListener sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):Processing IFRAME onload event SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):Clear IFrameLoadTimeout 11 SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):Start to ping the IFRAME https://appdomain/SQLTextBox/_layouts/15/AppWebProxy.aspx SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):Create IFramePingTimeout 49 SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.PostMessage.Message: {"command":"Ping","postMessageId":"SP.RequestExecutor2"} SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.PostMessage.Target: https://appdomain/SQLTextBox/_layouts/15/AppWebProxy.aspx SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.OnMessage sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.OnMessage: Message.data={"command":"Ping","postMessageId":"SP.RequestExecutor2"} sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.OnMessage: Message.origin=https://appdomain sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.OnMessage: Processing ping command sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.PostMessage.Message: {"command":"Ping","postMessageId":"SP.RequestExecutor2","responseAvailable":false,"errorCode":0,"errorMessage":""} sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.PostMessage.Target: https://appdomain sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.OnMessage SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.OnMessage: Message.data={"command":"Ping","postMessageId":"SP.RequestExecutor2","responseAvailable":false,"errorCode":0,"errorMessage":""} SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.OnMessage: Message.origin=https://appdomain SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):Successfully load frame for https://appdomain/SQLTextBox/_layouts/15/AppWebProxy.aspx SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.PostMessage.Message: {"command":"Query","url":"https://appdomain/SQLTextBox/_api/contextinfo","method":"POST","body":null,"headers":{"ACCEPT":"application/json;odata=verbose"},"postMessageId":"SP.RequestExecutor1","timeout":180000} SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.PostMessage.Target: https://appdomain/SQLTextBox/_layouts/15/AppWebProxy.aspx SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.OnMessage sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.OnMessage: Message.data={"command":"Query","url":"https://appdomain/SQLTextBox/_api/contextinfo","method":"POST","body":null,"headers":{"ACCEPT":"application/json;odata=verbose"},"postMessageId":"SP.RequestExecutor1","timeout":180000} sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.OnMessage: Message.origin=https://appdomain sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.PostMessage.Message: {"command":"Query","postMessageId":"SP.RequestExecutor1","responseAvailable":false,"errorCode":-1004,"errorMessage":"Your appdomain doesn't match the expected appdomain for this app deployment."} sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutorMessageProcessor.PostMessage.Target: https://appdomain sp.requestexecutor.js?rev=rvModk43dz0x3w5dN4u%2BBA%3D%3D:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.OnMessage SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.OnMessage: Message.data={"command":"Query","postMessageId":"SP.RequestExecutor1","responseAvailable":false,"errorCode":-1004,"errorMessage":"Your appdomain doesn't match the expected appdomain for this app deployment."} SP.RequestExecutor.js?_=1395693884243:2
Mon Mar 24 2014 15:48:27 GMT-0500 (Central Daylight Time):RequestExecutor.OnMessage: Message.origin=https://appdomain SP.RequestExecutor.js?_=1395693884243:2