-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.ts
52 lines (41 loc) · 1.49 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { JsomNode } from 'sp-jsom-node';
import { getAuth } from '../common/auth';
import { getRelativeUrl } from '../common/utils';
(async () => {
const { siteUrl, authOptions } = await getAuth.getContext();
new JsomNode().init({ siteUrl, authOptions });
const ctx = new SP.ClientContext(siteUrl);
const list = ctx.get_web().getList(`${getRelativeUrl(siteUrl)}/Lists/GuineaPigs`);
const guineaPigs = [ 'Braveheart', 'Zipper', 'Rocko' ];
const camlQuery = new SP.CamlQuery();
camlQuery.set_viewXml(`
<View Scope='RecursiveAll'>
<Query>
<Where>
<In>
<FieldRef Name='Title' />
<Values>
${guineaPigs.map((name) => {
return `<Value Type='Text'>${name}</Value>`;
}).join('')}
</Values>
</In>
</Where>
</Query>
</View>
`);
const items = list.getItems(camlQuery);
ctx.load(items, 'Include(ID,Title)');
await ctx.executeQueryPromise();
items.get_data().forEach((item) => {
const { ID, Title } = item.get_fieldValues();
console.log(`Updating: ${Title} (${ID})`);
item.set_item('DataField01', `Updated with JSOM request, ${new Date().toISOString()}`);
// item.update();
// item['updateOverwriteVersion']();
(item as any).systemUpdate(); // item.systemUpdate() just is not added in typings yet
});
await ctx.executeQueryPromise();
console.log('Done');
})()
.catch(console.log);