문제

SharePoint 2013 (Office365에서)을위한 SharePoint 호스팅 앱을 개발하고 있지만 SharePoint 호스팅 앱 내에서 목록에 액세스하는 데 문제가 있습니다.

내 코드는 목록을 잘 인쇄하지만 'Composed Look'목록과 '마스터 페이지 갤러리'목록 만 표시 할 수 있습니다. SharePoint 사이트에서 작성한 목록에 액세스 할 수 없습니다.

및 '연락처'목록 (앱을 배포하는 SharePoint 사이트에 있음)에 액세스하려고하면이 예외가 있습니다.

목록 '연락처'가 URL이있는 사이트에 존재하지 않습니다. ' https://mysharepointsite-03ea186502297f.sharepoint.com/sphostedapp12

그것은 내 앱이 내 주요 사이트보다 다른 사이트에서 실행되는 것으로 보인 것으로 보인다. 그리고 그것은 내 주 웹 사이트에서 기존 목록에 액세스 할 수없는 이유입니다 ...

누군가가 이것을 해결하고 주 사이트의 기존 목록에 액세스하는 방법을 알고 있습니까?

감사합니다!

여기에 내 app.js 코드가 있습니다 :

'use strict';

var gobbe = window.gobbe || {};

gobbe.Contacts;
gobbe.ContactList = function () {
    // private members
    var createItem = function (lname, fname, bphone) {
        var ctx = new SP.ClientContext.get_current();
        var list = ctx.get_web().get_lists().getByTitle('Contacts');
        ctx.load(list);
        var listItemCreationInfo = new SP.ListItemCreationInformation();
        var newContact = list.addItem(listItemCreationInfo);
        newContact.set_item('Last Name', lname);
        newContact.set_item('First Name', fname);
        newContact.set_item('Business Phone', bphone);
        newContact.update();
        ctx.executeQueryAsync(success, error);
    },
    readAll = function () {
        // Not implemented
    },
    readAllSuccess = function () {
        // Not implemented
    },
    updateItem = function () {
        // Not implemented
    },
    updateItem = function (id, lname, fname, bphone) {
        // Not implemented
    },
    removeItem = function (id) {
        // Not implemented
    },
    success = function () {
        readAll();
    },
    error = function (sender, args) {
        alert(args.get_message());
    }

    // public interface
    return {
        createContact: createItem,
        updateContact: updateItem,
        deleteContact: removeItem
    }
}();

gobbe.Collections = function () {
    // private members
    var site,
        listCollection,

        getListCollection = function () {
            var ctx = new SP.ClientContext.get_current();
            site = ctx.get_web();
            ctx.load(site);
            listCollection = site.get_lists();
            ctx.load(listCollection,     'Include(Title,Id,Fields.Include(Title,Description))');
        ctx.executeQueryAsync(success, failure);
        },

        success = function () {
            var html = [];

            // List Information
            html.push('<ul>');
            var listEnumerator = listCollection.getEnumerator();
            while (listEnumerator.moveNext()) {
                // List Title
                html.push('<li>');
                html.push(listEnumerator.get_current().get_title());
                html.push('<ul>');

                // Fields Names
                var fieldEnumerator =     listEnumerator.get_current().get_fields().getEnumerator();
                while (fieldEnumerator.moveNext()) {
                    html.push('<li>');
                    html.push(fieldEnumerator.get_current().get_title());
                    html.push('</li>');
                }

                html.push('</ul></li>')
            }
            html.push('</ul>');

            // Show results
            $('#displayDiv').html(html.join(''));
        },

        failure = function (sender, args) {
            alert(args.get_message());
        }

    // public interface
    return {
        execute: getListCollection
    }
}();

$().ready(function () {
    // Show lists
    gobbe.Collections.execute();

    // Try to add a contact
    gobbe.ContactList.createContact('Cox', 'Brian', '555-555-5555');
    alert('Contact Created!');

    // Update it
    gobbe.ContactList.updateContact(1, 'Cox', 'Brian', '111-111-1111');
    alert('Contact Updated!');

    // Delete it
    gobbe.ContactList.deleteContact(1);
    alert('Contact Deleted!');
});
.

도움이 되었습니까?

해결책

앱은 호스트 웹에 비해 다른 도메인에서 작동합니다. 따라서 앱 웹에서 호스트 웹에있는 일부 목록에 액세스하려고하면 도메인 도메인이 연결됩니다. 일반적으로 브라우저는 보안상의 이유로 이러한 교차 도메인 호출을 허용하지 않습니다. 그러나 앱에서 호스트 웹과 상호 작용하려면이 호출을 수행하는 데 사용할 수있는 크로스 도메인 libarary 인 sp.requestexecutor.js라는 라이브러리가 있습니다. 앱 웹의 호스트 웹 데이터에 액세스하도록 이러한 교차 도메인 호출을 만드는 데 도움이되는 다음 링크를 살펴보십시오.

http://msdn.microsoft.com/en-in/library/ FP179927.aspx

http://www.mavention.com/ 블로그 / SharePoint-app-reading-data-host-web

http://blogs.msdn.com/b/officeAppss/Archive/2012/11/29/solving-cross-domain-problems-in-apps-for-sharepoint.aspx 도움이되기를 바랍니다.

다른 팁

앱 권한을 부여하는 것을 잊어 버린 것처럼 들리 었는데, 목록의 '연락처'가 URL이있는 사이트에 존재하지 않습니다.

앱을 설치할 때 특정 라이브러리 또는 목록에 액세스 할 수있는 권한을 묻는 메시지가 표시됩니다.

이와 같은 것을 추가해야합니다 ... 앱 매니페스트에서 마크 업이 어떻게 보이는 것의 예 :

<AppPermissionRequests> <AppPermissionRequest Scope="http://sharepoint/content/sitecollection/web/list" Right="Write"/></AppPermissionRequests>

호스트 웹에서 목록에 액세스하려면 "표준 토큰"에 의존하여 EHTE JSOM 또는 REST API를 사용하여 데이터에 액세스하십시오.

 //Get the URI decoded URLs.
                hostweburl =
                    decodeURIComponent(
                        getQueryStringParameter("SPHostUrl")
                );
                appweburl =
                    decodeURIComponent(
                        getQueryStringParameter("SPAppWebUrl")
                );
.

다음과 같이 사용할 수 있습니다 :

 // Initialize the RequestExecutor with the app web URL.
                executor = new SP.RequestExecutor(appweburl);

                // Issue the call against the host web.
                // To get the title using REST we can hit the endpoint:
                //      app_web_url/_api/SP.AppContextSite(@target)/web/title?@target='siteUrl'
                // The response formats the data in the JSON format.
                // The functions successHandler and errorHandler attend the
                //      success and error events respectively.
                executor.executeAsync(
                    {
                        url:
                            appweburl +
                            "/_api/SP.AppContextSite(@target)/web/title?@target='" +
                            hostweburl + "'",
                        method: "GET",
                        headers: { "Accept": "application/json; odata=verbose" },
                        success: successHandler,
                        error: errorHandler
                    }
                );
.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 sharepoint.stackexchange
scroll top