none
How to make Cross Sitecollection call ?

    Question

  • I am using JSOM to access a list that is in some other sitecollection. Whenever I try to do that it gives me error , Access Denied. I have given all the necessary rights to the SharePoint hosted app. My code is.

    function

    sharePointReady() {

        hostweburl =

                 decodeURIComponent(

                     getQueryStringParameter(

    'SPHostUrl')

             );

        appweburl =

            decodeURIComponent(

                getQueryStringParameter(

    'SPAppWebUrl')

         );

        targetUrl =

    http://xyz.in;


        scriptbase = hostweburl +

    '/_layouts/15/';

        $.getScript(scriptbase +

    'SP.Runtime.js',

           

    function() {

                $.getScript(scriptbase +

    'SP.js',

                   

    function() {

                        $.getScript(scriptbase +

    'SP.RequestExecutor.js', addItems);

                    });

            });

    }


    function

    getQueryStringParameter(param) {

       

    varparams = document.URL.split("?")[1].split("&");

       

    varstrParams = "";

       

    for(vari = 0; i < params.length; i = i + 1) {

           

    varsingleParam = params[i].split("=");

           

    if(singleParam[0] == param) {

               

    returnsingleParam[1];

            }

        }

    }


    function

    addItems() {

        context =

    newSP.ClientContext(appweburl);

        factory =

    newSP.ProxyWebRequestExecutorFactory(appweburl);

        context.set_webRequestExecutorFactory(factory);

        appContextSite =

    newSP.AppContextSite(context, targetUrl);

        web = appContextSite.get_web();

        list = web.get_lists().getByTitle(

    "demo");

       

    varitemCreateInfo;

       

    varlistItem;

        itemCreateInfo =

    newSP.ListItemCreationInformation();

        listItem = list.addItem(itemCreateInfo);

    //add list item to the list.


        listItem.set_item(

    "Title", "Sagar");//set values to corresponding keys


        listItem.update();

    //update the list after the adding the values.


        context.load(web);

        context.executeQueryAsync(Function.createDelegate(

    this, addItemsSuccessHandler),

                                  Function.createDelegate(

    this, addItemsErrorHandler));

     

     

    }


    function

    addItemsSuccessHandler() {

        alert(

    "Pass");

    }


    function

    addItemsErrorHandler(sender, args) {

        alert(

    "fail"+ args.get_message());

    }

    Tuesday, August 20, 2013 8:44 AM

Answers

All replies