-
Notifications
You must be signed in to change notification settings - Fork 0
/
contactForm.js
72 lines (68 loc) · 2.8 KB
/
contactForm.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
if (typeof (D365Practice) == 'undefined') {
D365Practice = {}
}
D365Practice.ContactForm = (function () {
var setMarketingPermissions = function (formExecutionContext) {
var formContext = formExecutionContext.getFormContext();
var isPrioritized = formContext.getAttribute("cr31a_isprioritized").getValue();
if (isPrioritized) {
var input = {
new_contactRef: {
"contactid": "f5973462-768e-eb11-b1ac-000d3ae92b46",
"@odata.type": "Microsoft.Dynamics.CRM.contact"
},
new_allowemail: true,
new_allowsms: true
};
var req = new XMLHttpRequest();
req.open("POST", Xrm.Page.context.getClientUrl() +
"/api/data/v9.2/new_setmarketingpermisssions", false);
addHeaders(req);
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 204) {
result = JSON.parse(this.responseText);
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send(JSON.stringify(input));
}
}
var getMarketingPermissions = function (formExecutionContext) {
debugger;
var formContext = formExecutionContext.getFormContext();
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() +
"/api/data/v9.2/new_getmarketingpermissions(new_contactid=f5973462-768e-eb11-b1ac-000d3ae92b46)", false);
addHeaders(req);
req.onreadystatechange = function () {
if (this.readyState === 4) {
this.onreadystatechange = null;
if (this.status === 200) {
result = JSON.parse(this.responseText);
if (result.new_allowemail || result.new_allowsms) {
formContext.getControl("cr31a_isprioritized").setDisabled(false);
} else {
formContext.getControl("cr31a_isprioritized").setDisabled(true);
}
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
req.send();
}
var addHeaders = function (req) {
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
}
return {
GetMarketingPermissions: getMarketingPermissions,
SetMarketingPermissions: setMarketingPermissions
}
})()