문제

Because I can't seem to do what I need to get done using the REST API, I am going to try to use the Project Server JSOM in an SPFx webpart.

I found instructions on how to load the SharePoint JSOM into an SPFx web part by using SPComponentLoader, but that example shows SP.js as having several dependencies that need to be loaded first:

  • init.js
  • MicrosoftAjax.js
  • SP.Runtime.js

The example I found of how to get started using the Project Server JSOM only talks about loading the PS.js file:

<SharePoint:ScriptLink name="PS.js" runat="server" ondemand="false" localizable="false" loadafterui="true" />

and then making sure it's loaded by using executeOrDelayUntilScriptLoaded:

SP.SOD.executeOrDelayUntilScriptLoaded(MyFunction, "PS.js");

with no mention of any dependencies.

The MS documentation for PS.js Javascript library also does not mention any dependencies.

So, are there any unmentioned dependencies I would need to load before PS.js in order to use the Project Server JSOM in SPFx?

도움이 되었습니까?

해결책

I found my answer. Started playing around with it by only loading PS.js, but when trying to do a simple

const ctx = new PS.ProjectContext('https://server/pwa/my-pwa-instance');

I got a reference error 'SP' is not defined. So if SP is required, I figured all the other dependencies are required as well.

private componentDidMount = (): void => {
    SPComponentLoader.loadScript('/_layouts/15/init.js', {
        globalExportsName: '$_global_init'
    })
    .then((): Promise<{}> => {
        return SPComponentLoader.loadScript('/_layouts/15/MicrosoftAjax.js', {
            globalExportsName: 'Sys'
        });
    })
    .then((): Promise<{}> => {
        return SPComponentLoader.loadScript('/_layouts/15/SP.Runtime.js', {
            globalExportsName: 'SP'
        });
    })
    .then((): Promise<{}> => {
        return SPComponentLoader.loadScript('/_layouts/15/SP.js', {
            globalExportsName: 'SP'
        });
    })
    .then((): Promise<{}> => {
        return SPComponentLoader.loadScript('/_layouts/15/PS.js', {
            globalExportsName: 'PS'
        });
    })
    .then((): void => {
        // do my other init stuff
    });
}

After loading all dependencies like this, creating a new PS.ProjectContext at the very least seems to work.

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