jsom-helpers
v1.0.0
Published
Helper functions for JSOM async/await support for executeQueryAsync
Downloads
6
Readme
jsom-helpers
Helper functions for JSOM async/await support for executeQueryAsync
npm i jsom-helpers
load (context object, optional includes) : Promise
Combines call to executeQueryAync
and ctx.load
.
Multiple load
s will run in parallel.
import { load } from 'jsom-helpers';
(async () => {
const ctx = new SP.ClientContext();
const web = await load(ctx.get_web());
console.log(web.get_title());
const items = await load(
ctx.get_web().getList('/Lists/Test').getItems(new SP.CamlQuery()),
'Include(Title)'
);
// items Automatically converted to Array
console.log(items.map(item => item.get_fieldValues()));
})();
exec (context object) : Promise
Run executeQueryAsync
as a Promise.
Similar to load
, just more manual approach.
import { exec } from 'jsom-helpers';
(async () => {
const ctx = new SP.ClientContext();
const web = ctx.get_web();
ctx.load(web);
await exec(ctx);
console.log(web.get_title());
})();