Hi!
Please help in the following matter.
I have a form on SP2019 and in its custom JS I import a custom script file. In that script file I would like to use the pnp library, but unfortunately I cannot. How to do this?
This is my custom JS on the form:
window.$ = $;
window.jQuery = jQuery;
window.pnp=pnp;
fd.spRendered(function() {
$.getScript('https://sharepoint.contoso.com/start/SiteAssets/MyScript.js')
});
This is the script file MyScript.js:
console.log('Script loads');
const web = new Web('https://sharepoint.contoso.com/start/');
console.log('Second log');
const items = await web.lists.getByTitle("Listname").items.select("ID,Title").top(1).get();
console.log(JSON.stringify(items));
In the console only the 'Script loads" text appears the 'Second log' text does not. If I do not use imported script file and put everything in the custom JS then it works. It seems I cannot use pnp library in the imported script.
What should I do?
Thanks!