Follow Us:
SharePoint Add-Ins, though very interesting, are very tricky. Let me get directly to the point. If you are developing a SharePoint Hosted add-in, that needs to make a call outside the app web, be it host web or any other API call, there are certain things that need to be completed. Otherwise, you will have everything in place but will keep producing the Error-Not Found message when you run your SharePoint hosted add-in.
Understanding the Error Message:
This error will be produced when your Add-In cannot find the targeted list or any other SharePoint component that is being targeted in an App web or Host Web.
App Web: It is a web of app, that is, the web which is accessible to the app after it starts executing.
Host Web: It is a web of the host which is executing or which invokes execution of the app.
Cross-domain calls:
Let me give example of my application, when I encountered this issue.
In my application I am making call to user profiles in O365, for that purpose I needed my application to access UserProfile API and get back the results. This is how, it worked:
ScriptBase= HostWebUrl + "/_layouts/15/";
// Execute SP.RequestExecutor.js before your function executes
$.getScript(ScriptBase + "SP.RequestExecutor.js", execCrossDomainRequest);
// Execute Cross Domain Call function
function execCrossDomainRequest() {
var context1 = new SP.ClientContext(AppWebUrl);
try {
var factory = new SP.ProxyWebRequestExecutorFactory(AppWebUrl);
}
catch (err) {
alert(err.toString());
context1.set_webRequestExecutorFactory(factory);
var appContextSite = new SP.AppContextSite(context1, HostWebUrl);
this.web = appContextSite.get_web();
context1.load(this.web);
var executor = new SP.RequestExecutor(AppWebUrl);
executor.executeAsync(
{
url: AppWebUrl + "/_api/SP.AppContextSite(@target)/web/sitegroups/GetByName(GroupName)/users?@target='" + encodeURIComponent(HostWebUrl) + "'",
method: "GET",
crossDomain: true,
headers: { "accept": "application/json; odata=verbose" },
success: successHandler,
error: errorHandler
});
// Success Handler function
function successHandler(data)
var Parser= Json.Parse(data.body);
alert(Parser);
// Error Handler function
function errorHandler(data, errorcode, errormessage) {
alert("Error:" + errormessage);
Using the example above, you can make cross domain calls and tackle the famous "Not Found" error. Enjoy coding!
For more information about this blog or C5 Insight, please Contact Us!
The complementary paper includes over 12 years of research, recent survey results, and CRM turnaround success stories.
Request Download
This 60-second assessment is designed to evaluate your organization's collaboration readiness.
Learn how you rank compared to organizations typically in years 1 to 5 of implementation - and which areas to focus on to improve.
This is a sandbox solution which can be activated per site collection to allow you to easily collect feedback from users into a custom Feedback list.
Whether you are upgrading to SharePoint Online, 2010, 2013 or the latest 2016, this checklist contains everything you need to know for a successful transition.