-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathContactScripts.js
70 lines (53 loc) · 2.42 KB
/
ContactScripts.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
function ButtonClick()
{
alert("Function call from button")
}
function OnContactLoad() {
var accountid = Xrm.Page.data.entity.attributes.get("parentcustomerid").getValue()[0].id;
var accid = accountid.replace("{", "").replace("}", "");
var req = new XMLHttpRequest();
req.open("GET", Xrm.Page.context.getClientUrl() + "/api/data/v8.2/accounts(" + accid +")?$select=accountnumber,address1_city,address1_line1,address1_postalcode,name", true);
req.setRequestHeader("OData-MaxVersion", "4.0");
req.setRequestHeader("OData-Version", "4.0");
req.setRequestHeader("Accept", "application/json");
req.setRequestHeader("Content-Type", "application/json; charset=utf-8");
req.setRequestHeader("Prefer", "odata.include-annotations=\"*\"");
req.send(null);
req.onreadystatechange = function () {
if (this.readyState === 4) {
req.onreadystatechange = null;
if (this.status === 200) {
var result = JSON.parse(this.response);
var accountnumber = result["accountnumber"];
var address1_city = result["address1_city"];
var address1_line1 = result["address1_line1"];
var address1_postalcode = result["address1_postalcode"];
var name = result["name"];
Xrm.Page.ui.setFormNotification("Account Number: " + accountnumber + "\n" + "Address :" + address1_city + "," + address1_line1, "INFO", "2");
} else {
Xrm.Utility.alertDialog(this.statusText);
}
}
};
}
function OnLastNameChange() {
}
function OnPhoneChange() {
var telephone = Xrm.Page.getAttribute("telephone1").getValue();
if (isNaN(telephone)) {
Xrm.Page.getControl("telephone1").setNotification("Enter proper phone number", "1");
}
else {
Xrm.Page.getControl("telephone1").clearNotification("1");
}
}
function OnShippingMethodChange() {
var method = Xrm.Page.getAttribute("address1_shippingmethodcode").getText();
if (method == "DHL") {
Xrm.Page.getControl("address1_freighttermscode").setDisabled(true);
Xrm.Page.ui.setFormNotification("Freight Terms are only available for DHL for the moment. Please contact administrator for more information.", "INFO", "2");
} else {
Xrm.Page.getControl("address1_freighttermscode").setDisabled(false);
Xrm.Page.ui.clearFormNotification("2");
}
}