-
Notifications
You must be signed in to change notification settings - Fork 0
/
barcodeScanner.js
54 lines (48 loc) · 1.93 KB
/
barcodeScanner.js
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
async function saveToLog(executionContext) {
try {
const trackerNumber = executionContext.getFormContext().getAttribute("wcs_sampletrackernumber").getValue();
const userName = Xrm.Utility.getGlobalContext().userSettings.userName;
const BPFStage = Xrm.Page.data.process.getActiveStage();
const fetchXml = [
"<fetch>",
"<entity name='wcs_barcodescannerapp_tempdirectory'>",
"<filter>",
"<condition attribute='wcs_sampletrackernumber' operator='eq' value='", trackerNumber, "'/>",
"<condition attribute='wcs_user' operator='eq' value='", userName, "'/>",
"<condition attribute='wcs_commitchange' operator='eq' value='0'/>",
"</filter>",
"</entity>",
"</fetch>",
].join("");
const fetchUrl = Xrm.Page.context.getClientUrl()
+ "/api/data/v9.2/wcs_barcodescannerapp_tempdirectories?fetchXml="
+ encodeURIComponent(fetchXml);
const data = await fetch(
fetchUrl,
{
credentials: "same-origin",
headers: {
Prefer: 'odata.include-annotations="*"'
}
}
)
.then(response => response.json());
if (data.error) {
throw Error(data.error.message);
}
if (data.value.length) {
showObj(userName, trackerNumber, BPFStage);
}
} catch(e) {
Xrm.Navigation.openAlertDialog("Error: " + e.message);
}
}
function showObj(userName, trackerNumber, BPFStage) {
window.open(
'https://apps.powerapps.com/play/6157001e-2a22-4471-8b73-422f47786b9c?source=JS&user='
+ userName + '&record=' + trackerNumber + '&stage=' + BPFStage, '&FormType="Sample"' + "",
"width=800,height=600",
"menubar=no",
"toolbar=no"
);
}