質問

SharePoint 2013 (Office365) 用の SharePoint ホスト型アプリを開発していますが、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!');
});
役に立ちましたか?

解決

アプリケーションは、ホストWebと比較して別のドメインで機能します。そのため、App WebからホストWebにあるいくつかのリストにアクセスしようとすると、クロスドメイン呼び出し。 通常ブラウザにセキュリティ上の理由からこれらのクロスドメインが呼び出すことを許可しません。ただし、アプリでは、ホストWebと対話するために、Sp.requestExecutor.jsというライブラリがあります。これは、これらの呼び出しを行うために使用できるクロスドメインのLibrararyです。 これらのクロスドメインがアプリWeb内のホストWebデータにアクセスするのに役立つ次のリンクを参照してください。

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

href="http://www.maventy.com/blog/sharepoint.com/blog/sharepoint-app-reading-Data-from-host-web" real="nofollow">> http://www.mavention.com/ブログ/ SharePoint-App-Reading-Data-From-host-web

http://blogs.msn.com/b/officeapps/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>

ホストWebからリストにアクセスするには、「標準トークン」に頼る必要があり、ETHE 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