-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathservice activity.js
More file actions
159 lines (113 loc) · 4.52 KB
/
service activity.js
File metadata and controls
159 lines (113 loc) · 4.52 KB
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
if (typeof (RSA) == "undefined") {
RSA = { __namespace: true };
}
//ENUMS
formType = {
CREATE: 1,
UPDATE: 2,
READONLY: 3,
DISABLED: 4
}
//CONSTANTS
const NBSAPPOINTMENT = "rsa_nbsappointment";
const NBSAPPOINTMENTTYPE = "rsa_appointmenttype";
var XP = Xrm.Page;
RSA.ServiceActivity = {
//onLoad function for this form
onLoad: function () {
var formtype = Xrm.Page.ui.getFormType();
if (formtype == formType.CREATE) {
this.hideAndShowNbsAppointmentId();
}
else if (formtype == formType.UPDATE) {
this.hideAndShowNbsAppointmentId();
this.disableAppointmentType();
}
else if (formtype == formType.READONLY) {
}
else if (formtype == formType.DISABLED) {
}
},
//onSave function for this form
onSave: function () {
var formtype = Xrm.Page.ui.getFormType();
if (formtype == formType.CREATE) {
}
else if (formtype == formType.UPDATE) {
}
else if (formtype == formType.READONLY) {
}
else if (formtype == formType.DISABLED) {
}
},
// hide appointment type if value is "Call back" else show and make it required
hideAndShowNbsAppointmentId: function () {
var hideAppointmentId = Xrm.Page.data.entity.attributes.get(NBSAPPOINTMENTTYPE).getValue();
if (hideAppointmentId == 866760002) {
Xrm.Page.getControl("rsa_nbsappointmentid").setVisible(false);
Xrm.Page.getAttribute("rsa_nbsappointmentid").setRequiredLevel("none");
}
else {
Xrm.Page.getControl("rsa_nbsappointmentid").setVisible(true);
Xrm.Page.getAttribute("rsa_nbsappointmentid").setRequiredLevel("required");
}
},
disableAppointmentType: function (){
Xrm.Page.getControl(NBSAPPOINTMENTTYPE).setDisabled(true);
},
//Function to get values from contact record to service activity (I
retrieveValuesFromContact: function () {
debugger;
var regardingObject = Xrm.Page.getAttribute("customers");
if (regardingObject != null && regardingObject.getValue() != null) {
var contactlookup = regardingObject.getValue()[0];
if (!IsNull(contactlookup)) {
if (contactlookup.entityType == "contact") {
var contactId = contactlookup.id;
RSA.ServiceActivity.retrieveRecords(contactId, RSA.ServiceActivity.retrieveCompleted, null, "ContactSet(guid'"+ contactId +"')?$select=MobilePhone,Telephone2,Telephone1");
}
}
}
},
retrieveCompleted: function (data, textStatus, XmlHttpRequest) {
debugger;
if (data != null) {
var mobileNumber = data.MobilePhone;
Xrm.Page.getAttribute("rsa_mobilenumber").setValue(mobileNumber);
var workNumber = data.Telephone1;
Xrm.Page.getAttribute("rsa_worknumber").setValue(workNumber);
var homeNumber = data.Telephone2;
Xrm.Page.getAttribute("rsa_homenumber").setValue(homeNumber);
}
},
retrieveRecords: function (id, successCallback, errorCallback, url) {
//var context = GetGlobalContext();
debugger;
var serverUrl = XP.context.getClientUrl();
var odataEndPoint = "/XRMServices/2011/OrganizationData.svc/";
if (!id) {
alert("record id is required.");
return;
}
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
datatype: "json",
url: serverUrl + odataEndPoint + "/" + url,
beforeSend: function (XMLHttpRequest) {
XMLHttpRequest.setRequestHeader("Accept", "application/json");
},
success: function (data, textStatus, XmlHttpRequest) {
if (successCallback) {
successCallback(data.d, textStatus, XmlHttpRequest);
}
},
error: function (XmlHttpRequest, textStatus, errorThrown) {
if (errorCallback)
errorCallback(XmlHttpRequest, textStatus, errorThrown);
else
errorHandler(XmlHttpRequest, textStatus, errorThrown);
}
});
}
}