none
Office Addin _spPageContextInfo Undefined RRS feed

  • Question

  • I am getting _spPageContextInfo Undefined on office Addins

    i added the below sharepoint js files into my project but still getting the same error _spPageContextInfo Undefined,

    <script src="Scripts/MicrosoftAjax.js"></script>
    <script src="Scripts/init.js"></script>
    <script src="Scripts/sp.core.js"></script>
    <script src="Scripts/sp.runtime.js"></script>
    <script src="Scripts/sp.js"></script>

    $(document).ready(function () {
       ExecuteOrDelayUntilScriptLoaded(runCode, "sp.js");
     
    });

       
    function runCode() {
                var userid = _spPageContextInfo.userId;
    }

    Most examples use sharepoint hosted addin but i would like to used Office Addin.

    Is there any js file i should add ? I couldn't use the guide because it only work for documents created with the addin content type https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/create-a-sharepoint-add-in-that-contains-a-document-template-and-a-task-pane-add


    • Edited by tapsb Thursday, February 22, 2018 7:36 AM
    Thursday, February 22, 2018 7:29 AM

Answers

All replies

  • Hi tapsb,

    What are you trying to develop?

    >>Most examples use sharepoint hosted addin but i would like to used Office Addin

    What do you mean by this line? For AddIns, I am afraid you could not mix SharePoint AddIn into Office AddIn, they are total different products.

    It would be helpful if you could share us what you want to achieve by Office AddIn.

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, February 23, 2018 5:19 AM
  • Hi Tao

    I need to develop an Word Add-in that get data from SharePoint Lists and populate it on word document.

    The challenge is to get spcontext on the Office Add-in.

    I followed this link to create the SharePoint Add-in that contains the word add-in, however it works for new documents only, it does not work for uploaded documents, so i decided to create an office add-in which will be deployed to the store, the challenge is to get SharePoint data from office word add-in.


     

    Friday, February 23, 2018 7:43 AM
  • Hi tapsb,

    It is impossible to use sp.js in Office AddIn.

    For getting data from Sharepoint lists, you could try SharePoint Rest Service in Office AddIn.

    # Working with lists and list items with REST

    https://docs.microsoft.com/en-us/sharepoint/dev/sp-add-ins/working-with-lists-and-list-items-with-rest

    Best Regards,

    Tao Zhou


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Marked as answer by tapsb Friday, February 23, 2018 11:05 AM
    Friday, February 23, 2018 7:49 AM