-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathsys.tsx
111 lines (90 loc) · 4.89 KB
/
sys.tsx
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
import * as React from 'react'
import { useContext, useEffect } from 'react'
import { HellowWorldContext } from '../../hooks/useHellowWorldContext';
import { ISPHttpClientOptions, SPHttpClient } from '@microsoft/sp-http';
export default function SystemUpdate() {
const { helloWorld } = useContext(HellowWorldContext);
function delay(ms: number): Promise<void> {
return new Promise(resolve => setTimeout(resolve, ms));
}
useEffect(() => {
const sysUpdate = async (): Promise<void> => {
try {
await delay(2000);
console.log("FazLog ~ sysUpdate ~ two seconds waited");
const listRelativeUrl = '/sites/gca-dev/Shared Documents';
const itemId = 2;
const siteUrl = "https://cafacloud.sharepoint.com/sites/gca-dev";
// const body = `
// <Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="Javascript Library"><Actions><Method Name="SetFieldValue" Id="4" ObjectPathId="3"><Parameters><Parameter Type="String">Title</Parameter><Parameter Type="String">UpdatedXML, ${new Date().toISOString()}</Parameter></Parameters></Method><Method Name="SystemUpdate" Id="5" ObjectPathId="3" /></Actions><ObjectPaths><Property Id="1" ParentId="0" Name="Web" /><Method Id="2" ParentId="1" Name="GetList"><Parameters><Parameter Type="String">${listRelativeUrl}</Parameter></Parameters></Method><Method Id="3" ParentId="2" Name="GetItemById"><Parameters><Parameter Type="Number">${itemId}</Parameter></Parameters></Method><StaticProperty Id="0" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" /></ObjectPaths></Request>`;
const body = `<Request xmlns="http://schemas.microsoft.com/sharepoint/clientquery/2009" SchemaVersion="15.0.0.0" LibraryVersion="16.0.0.0" ApplicationName="Javascript Library">
<Actions>
<Method Name="SetFieldValue" Id="4" ObjectPathId="3">
<Parameters>
<Parameter Type="String">Review</Parameter>
<Parameter Type="DateTime">${new Date(new Date().setDate(new Date().getDate() + 19)).toISOString()}</Parameter>
</Parameters>
</Method>
<Method Name="SetFieldValue" Id="5" ObjectPathId="3">
<Parameters>
<Parameter Type="String">Owner</Parameter>
<Parameter Type="Number">6</Parameter>
</Parameters>
</Method>
<Method Name="SystemUpdate" Id="6" ObjectPathId="3" />
</Actions>
<ObjectPaths>
<Property Id="1" ParentId="0" Name="Web" />
<Method Id="2" ParentId="1" Name="GetList">
<Parameters>
<Parameter Type="String">${listRelativeUrl}</Parameter>
</Parameters>
</Method>
<Method Id="3" ParentId="2" Name="GetItemById">
<Parameters>
<Parameter Type="Number">${itemId}</Parameter>
</Parameters>
</Method>
<StaticProperty Id="0" TypeId="{3747adcd-a3c3-41b9-bfab-4a64dd2f1e0a}" Name="Current" />
</ObjectPaths>
</Request>`;
const endpoint = `${siteUrl}/_vti_bin/client.svc/ProcessQuery`;
// const client = new SPHttpClient();
const spOpts: ISPHttpClientOptions = {
body: body
};
await helloWorld?.context.spHttpClient.post(endpoint, SPHttpClient.configurations.v1, spOpts);
// .then((response: SPHttpClientResponse) => {
// // Access properties of the response object.
// console.log(`Status code: ${response.status}`);
// console.log(`Status text: ${response.statusText}`);
// //response.json() returns a promise so you get access to the json in the resolve callback.
// response.json().then((responseJSON: JSON) => {
// console.log(responseJSON);
// });
// });
// client.post(endpoint, {
// headers: {
// 'Accept': '*/*',
// 'Content-Type': 'text/xml;charset="UTF-8"',
// 'X-Requested-With': 'XMLHttpRequest'
// },
// body
// })
// .then(r => r.json())
// .then(r => {
// if (r[0].ErrorInfo) {
// throw new Error(r[0].ErrorInfo.ErrorMessage);
// }
// return r;
// });
} catch (error) {
console.log("FazLog ~ sysUpdate ~ error:", error);
}
}
sysUpdate().catch(e => console.error(e));
}, []);
return (
<div>SystemUpdate</div>
)
}