none
Explain when to use WebRequestExecutorFactory & SP.ProxyWebRequestExecutorFactory RRS feed

  • Question

  • Hi,

    Can someone please explain to me when I should and should not use the classes and methods with the word Factory in, like   

    • WebRequestExecutorFactory
    • set_webRequestExecutorFactory
    • SP.ProxyWebRequestExecutorFactory

    It would also help if you could include a simple demo or code snippet.

    I hope you can help
    Colin



    • Edited by ceBlueSky Sunday, December 18, 2016 5:02 PM
    Sunday, December 18, 2016 5:00 PM

Answers

  • Hi,

    In SharePoint add-in, we need cross domain library to get SharePoint content in the add-in.

    Like the code snippet below:

    function GetListData() {
        context = new SP.ClientContext(appweburl);
        factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
        context.set_webRequestExecutorFactory(factory);
        appContextSite = new SP.AppContextSite(context, hostweburl);
        web = appContextSite.get_web();
        list = web.get_lists().getByTitle("YOUR_LIST_NAME");
        var camlString = "YOUR_CAML QUERY GOES HERE";
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml(camlString);
        listitemcollection = list.getItems(camlQuery);
        context.load(listitemcollection, "Include(FIELD_1, FIELD_2, FIELD_3)");
        context.executeQueryAsync(GetListSuccess, GetListError);
    }
    

    The following articles for your reference:

    Working with JSOM (JavaScript Object Model) on SharePoint Apps

    http://www.bipul.in/2015/07/working-with-jsom-javascript-object.html

    Cross Domain and SharePoint Hosted Apps using CSOM

    https://cann0nf0dder.wordpress.com/2013/04/20/cross-domain-and-sharepoint-hosted-apps-using-csom/

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by ceBlueSky Tuesday, December 20, 2016 10:31 AM
    Tuesday, December 20, 2016 6:54 AM
    Moderator

All replies

  • Hi,

    In SharePoint add-in, we need cross domain library to get SharePoint content in the add-in.

    Like the code snippet below:

    function GetListData() {
        context = new SP.ClientContext(appweburl);
        factory = new SP.ProxyWebRequestExecutorFactory(appweburl);
        context.set_webRequestExecutorFactory(factory);
        appContextSite = new SP.AppContextSite(context, hostweburl);
        web = appContextSite.get_web();
        list = web.get_lists().getByTitle("YOUR_LIST_NAME");
        var camlString = "YOUR_CAML QUERY GOES HERE";
        var camlQuery = new SP.CamlQuery();
        camlQuery.set_viewXml(camlString);
        listitemcollection = list.getItems(camlQuery);
        context.load(listitemcollection, "Include(FIELD_1, FIELD_2, FIELD_3)");
        context.executeQueryAsync(GetListSuccess, GetListError);
    }
    

    The following articles for your reference:

    Working with JSOM (JavaScript Object Model) on SharePoint Apps

    http://www.bipul.in/2015/07/working-with-jsom-javascript-object.html

    Cross Domain and SharePoint Hosted Apps using CSOM

    https://cann0nf0dder.wordpress.com/2013/04/20/cross-domain-and-sharepoint-hosted-apps-using-csom/

    Best Regards,

    Dennis


    Please remember to mark the replies as answers if they help.
    If you have feedback for TechNet Subscriber Support, contact tnmff@microsoft.com

    • Marked as answer by ceBlueSky Tuesday, December 20, 2016 10:31 AM
    Tuesday, December 20, 2016 6:54 AM
    Moderator
  • Have the same code  like this... my investigations led me to it independently of your response... but I am getting Access denied no matter what I try... 
    Friday, May 26, 2017 1:07 PM
  • I would suggest giving write permissions to Tenant may help this Access denied issue.
    Thursday, May 17, 2018 10:58 AM