@inizioevoke/veeva-astroclm 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude/settings.local.json +10 -0
- package/.claude/skills/evoke-analytics-auditor/SKILL.md +509 -0
- package/.claude/skills/evoke-astro-core/SKILL.md +395 -0
- package/.claude/skills/evoke-page-manager/SKILL.md +75 -0
- package/.claude/skills/evoke-veeva-config-manager/SKILL.md +17 -0
- package/.claude/skills/evoke-veeva-config-manager/create.md +189 -0
- package/.claude/skills/evoke-veeva-config-manager/manage.md +48 -0
- package/.editorconfig +12 -0
- package/.env.development +3 -0
- package/.env.veeva-client +1 -0
- package/.env.veeva-client-training +2 -0
- package/.env.veeva-evoke +4 -0
- package/README.md +43 -0
- package/_contents.yml.example +6 -0
- package/astro.config.ts +36 -0
- package/package.json +40 -0
- package/public/astroclm.png +0 -0
- package/public/favicon.png +0 -0
- package/public/shared/salesforce.js +2586 -0
- package/public/shared/vault.js +2417 -0
- package/src/components/content/readme.md +1 -0
- package/src/components/isi/ISIContent.tsx +137 -0
- package/src/components/isi/_isi.scss +22 -0
- package/src/components/nav/MainNav/MainNav.astro +20 -0
- package/src/components/nav/MainNav/MainNav.tsx +36 -0
- package/src/components/nav/NavList.tsx +66 -0
- package/src/components/ui/Button.astro +19 -0
- package/src/components/ui/Image.astro +36 -0
- package/src/components/ui/IvaConsole/IvaConsole.astro +12 -0
- package/src/components/ui/IvaConsole/IvaConsole.scss +62 -0
- package/src/components/ui/IvaConsole/IvaConsole.ts +144 -0
- package/src/components/ui/Link.astro +39 -0
- package/src/components/ui/Link.tsx +36 -0
- package/src/components/ui/NavLink.astro +46 -0
- package/src/components/ui/NavLink.tsx +41 -0
- package/src/components/ui/VeevaControls/VeevaControls.astro +48 -0
- package/src/components/ui/VeevaControls/VeevaControls.scss +145 -0
- package/src/components/ui/VeevaLink.astro +36 -0
- package/src/data/pages.tsx +50 -0
- package/src/env.d.ts +14 -0
- package/src/lib/client/context.ts +45 -0
- package/src/lib/client/main.ts +54 -0
- package/src/lib/client/readme.md +1 -0
- package/src/lib/client/swipe-nav.ts +35 -0
- package/src/lib/client/utils.ts +58 -0
- package/src/lib/server/readme.md +1 -0
- package/src/lib/server/screen.ts +10 -0
- package/src/middleware.ts.bak +12 -0
- package/src/scss/_mixins.scss +1 -0
- package/src/scss/_variables.scss +6 -0
- package/src/scss/ipads.scss +89 -0
- package/src/shared/img/veeva/veeva-action.png +0 -0
- package/src/shared/img/veeva/veeva-desktop-action.png +0 -0
- package/src/shared/img/veeva/veeva-desktop-navigation.png +0 -0
- package/src/shared/img/veeva/veeva-desktop-next.png +0 -0
- package/src/shared/img/veeva/veeva-desktop-previous.png +0 -0
- package/src/shared/img/veeva/veeva-highlighter.png +0 -0
- package/src/shared/img/veeva/veeva-history-back.png +0 -0
- package/src/shared/img/veeva/veeva-history-forward.png +0 -0
- package/src/shared/img/veeva/veeva-navigation.png +0 -0
- package/src/shared/img/veeva/veeva-reactions.png +0 -0
- package/tasks/page-manager.ts +4 -0
- package/tasks/util.ts +7 -0
- package/tasks/veeva-config.ts +4 -0
- package/tasks/veeva-deploy.ts +21 -0
- package/tsconfig.json +23 -0
- package/veeva-metadata.js +461 -0
|
@@ -0,0 +1,2417 @@
|
|
|
1
|
+
// Vault CRM JavaScript Library version 253.2.52-2
|
|
2
|
+
// http://veeva.com
|
|
3
|
+
//
|
|
4
|
+
// Copyright © 2024 Veeva Systems, Inc. All rights reserved.
|
|
5
|
+
//
|
|
6
|
+
// The com.veeva.clm namespace should be utilized when calling the JavaScript functions.
|
|
7
|
+
// Example: "com.veeva.clm.getDataForCurrentObject("Account","id", myAccountID);"
|
|
8
|
+
//
|
|
9
|
+
//
|
|
10
|
+
// JavaScript library will return in the following format:
|
|
11
|
+
// {success:true, obj_name:[{"id":"0001929312"}, {record2}, ...]}
|
|
12
|
+
// or
|
|
13
|
+
// {success:false, code:####, message:"message_text"}
|
|
14
|
+
// #### - denotes the specific error code (1000 is from the underlying API, 2000 is from the JavaScript library)
|
|
15
|
+
// 2000 - Callback function is missing
|
|
16
|
+
// 2001 - Callback is not a JavaScript function
|
|
17
|
+
// 2002 - <parameter_name> is empty
|
|
18
|
+
// 2100 - Request (%@) failed: %@
|
|
19
|
+
// message_text - begins with the JavaScript library function name and a ":". If the error comes from the underlying API, the full message
|
|
20
|
+
// from the API will be appended to the message_text
|
|
21
|
+
//
|
|
22
|
+
//
|
|
23
|
+
// For CLM:
|
|
24
|
+
// With the exception of gotoSlide, the JavaScript functions respect My Setup, Restricted Products on Account, Allowed Products on Call and on TSF.
|
|
25
|
+
// goToSlide respects all of the above when media is launched from a Call or an Account. goToSlide does not respect Restricted Products
|
|
26
|
+
// and Allowed Products when media is launched from the home page.
|
|
27
|
+
//
|
|
28
|
+
//
|
|
29
|
+
// Use the JavaScript functions in a chain, i.e. call the second JavaScript function only in the first function's callback function or
|
|
30
|
+
// after the callback of the first function is finished.
|
|
31
|
+
// Because the underlying API calls are asynchronous, this may result in unexpected return values if the JavaScript functions are
|
|
32
|
+
// not properly chained.
|
|
33
|
+
//
|
|
34
|
+
//
|
|
35
|
+
// Veeva recommends caution when retrieving/saving data using the following field types and to always perform rigorous testing:
|
|
36
|
+
// Long Text Area
|
|
37
|
+
// Rich Text Area
|
|
38
|
+
// Encrypted Text Area
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
const FEATURE_MULTI_PRODUCT_MIN_VERSION = "212.0.100";
|
|
42
|
+
var com;
|
|
43
|
+
if(com == null) com = {};
|
|
44
|
+
if(com.veeva == undefined)com.veeva = {};
|
|
45
|
+
com.veeva.clm = {
|
|
46
|
+
/////////////////////// Addresses ///////////////////////
|
|
47
|
+
|
|
48
|
+
// 1
|
|
49
|
+
// Returns an array of record IDs of all addresses (address__v) for a particular account (account__v)
|
|
50
|
+
// account - specifies the record id of the account of which to get all related addresses
|
|
51
|
+
// callback - call back function which will be used to return the information
|
|
52
|
+
getAddresses_Account: function(account, callback) {
|
|
53
|
+
ret = this.checkCallbackFunction(callback);
|
|
54
|
+
if(ret.success == false)
|
|
55
|
+
return ret;
|
|
56
|
+
|
|
57
|
+
// check arguments
|
|
58
|
+
ret = this.checkArgument("account", account);
|
|
59
|
+
if(ret.success == false) {
|
|
60
|
+
com.veeva.clm.wrapResult("getAddresses_Account", callback, ret);
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
window["com_veeva_clm_accountAddresses"] = function(result) {
|
|
64
|
+
com.veeva.clm.wrapResult("getAddresses_Account", callback, result);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
query = "vaultcrm:queryObject(address__v),fields(id),where(WHERE account__v='" + account + "'),com_veeva_clm_accountAddresses(result)";
|
|
68
|
+
if(!com.veeva.clm.testMode)
|
|
69
|
+
com.veeva.clm.runAPIRequest(query);
|
|
70
|
+
else
|
|
71
|
+
com_veeva_clm_accountAddresses(com.veeva.clm.testResult.common);
|
|
72
|
+
},
|
|
73
|
+
|
|
74
|
+
// 2
|
|
75
|
+
// Returns the values of the specified fields for specified Address (address__v) record
|
|
76
|
+
// record - specifies the record id of the Address to get fields from
|
|
77
|
+
// fields - list of field api names to return a value for, this parameter should be an array
|
|
78
|
+
// callback - call back function which will be used to return the information
|
|
79
|
+
getAddressFields: function(record, fields, callback) {
|
|
80
|
+
ret = this.checkCallbackFunction(callback);
|
|
81
|
+
if(ret.success == false)
|
|
82
|
+
return ret;
|
|
83
|
+
|
|
84
|
+
// check arguments
|
|
85
|
+
ret = this.checkArgument("record", record);
|
|
86
|
+
if(ret.success == false) {
|
|
87
|
+
com.veeva.clm.wrapResult("getAddressFields", callback, ret);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if(fields == undefined || fields == null) {
|
|
91
|
+
fields = ["id"];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
window["com_veeva_clm_addressValues"] = function(result) {
|
|
95
|
+
com.veeva.clm.wrapResult("getAddressFields", callback, result);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
query = "vaultcrm:queryObject(address__v),fields(" + this.joinFieldArray(fields) + "),where(WHERE id='" + record + "'),com_veeva_clm_addressValues(result)";
|
|
99
|
+
if(!com.veeva.clm.testMode)
|
|
100
|
+
com.veeva.clm.runAPIRequest(query);
|
|
101
|
+
else
|
|
102
|
+
com_veeva_clm_addressValues(com.veeva.clm.testResult.common);
|
|
103
|
+
},
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
/////////////////////// Products ///////////////////////
|
|
107
|
+
|
|
108
|
+
// Returns an array of record IDs of all products (product__v) of a specified type that the User has access to
|
|
109
|
+
// type - specifies the Product Type (product_type__v field on product__v)
|
|
110
|
+
// callback - call back function which will be used to return the information
|
|
111
|
+
getProduct_MySetup: function(type, callback) {
|
|
112
|
+
// check parameter
|
|
113
|
+
|
|
114
|
+
ret = this.checkCallbackFunction(callback);
|
|
115
|
+
if(ret.success == false)
|
|
116
|
+
return ret;
|
|
117
|
+
|
|
118
|
+
// check arguments
|
|
119
|
+
ret = this.checkArgument("type", type);
|
|
120
|
+
if(ret.success == false) {
|
|
121
|
+
com.veeva.clm.wrapResult("getProduct_MySetup", callback, ret);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
window["com_veeva_clm_productMysetup"] = function(result) {
|
|
127
|
+
com.veeva.clm.wrapResult("getProduct_MySetup", callback, result);
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
query = "vaultcrm:queryObject(product__v),fields(id),where(WHERE product_type__v='" + type + "'),com_veeva_clm_productMysetup(result)";
|
|
132
|
+
if(!com.veeva.clm.testMode)
|
|
133
|
+
com.veeva.clm.runAPIRequest(query);
|
|
134
|
+
else
|
|
135
|
+
com_veeva_clm_productMysetup(com.veeva.clm.testResult.common);
|
|
136
|
+
|
|
137
|
+
},
|
|
138
|
+
|
|
139
|
+
/////////////////////// Object Type Support ///////////////////////
|
|
140
|
+
|
|
141
|
+
// Returns an array of record IDs of all object_type__v records (ObjectType) for a particular object
|
|
142
|
+
// object - specifies the API name of the object of which to get all active ObjectTypes
|
|
143
|
+
// callback - call back function which will be used to return the information
|
|
144
|
+
getObjectType_Object: function(object, callback) {
|
|
145
|
+
|
|
146
|
+
ret = this.checkCallbackFunction(callback);
|
|
147
|
+
if(ret.success == false)
|
|
148
|
+
return ret;
|
|
149
|
+
|
|
150
|
+
// check arguments
|
|
151
|
+
ret = this.checkArgument("object", object);
|
|
152
|
+
if(ret.success == false) {
|
|
153
|
+
com.veeva.clm.wrapResult("getObjectType_Object", callback, ret);
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
window["com_veeva_clm_objectObjectTypes"] = function(result) {
|
|
158
|
+
com.veeva.clm.wrapResult("getObjectType_Object", callback, result);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
query = "vaultcrm:queryObject(object_type__v),fields(id),where(WHERE object_name__v='" + object + "' and status__v='active__v'),com_veeva_clm_objectObjectTypes(result)";
|
|
162
|
+
if(!com.veeva.clm.testMode)
|
|
163
|
+
com.veeva.clm.runAPIRequest(query);
|
|
164
|
+
else
|
|
165
|
+
com_veeva_clm_objectObjectTypes(com.veeva.clm.testResult.common);
|
|
166
|
+
},
|
|
167
|
+
|
|
168
|
+
// Wrapper for backward compatibility with the Salesforce-based CLM content
|
|
169
|
+
getRecordType_Object: function(object, callback) {
|
|
170
|
+
this.getObjectType_Object(object, callback);
|
|
171
|
+
},
|
|
172
|
+
|
|
173
|
+
/////////////////////// Surveys ///////////////////////
|
|
174
|
+
|
|
175
|
+
// 1
|
|
176
|
+
// Returns an array of record IDs of all Survey Questions (survey_question__v) for a specific Survey (survey__v)
|
|
177
|
+
// Results are returned in ascending order based on the order__v field on survey_question__v.
|
|
178
|
+
// survey - specifies the record id of the Survey to get all related Survey Questions from
|
|
179
|
+
// callback - call back function which will be used to return the information
|
|
180
|
+
getSurveyQuestions_Survey: function(survey, callback) {
|
|
181
|
+
ret = this.checkCallbackFunction(callback);
|
|
182
|
+
if(ret.success == false)
|
|
183
|
+
return ret;
|
|
184
|
+
|
|
185
|
+
// check arguments
|
|
186
|
+
ret = this.checkArgument("survey", survey);
|
|
187
|
+
if(ret.success == false) {
|
|
188
|
+
com.veeva.clm.wrapResult("getSurveyQuestions_Survey", callback, ret);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
window["com_veeva_clm_surveyQuestions"] = function(result) {
|
|
193
|
+
com.veeva.clm.wrapResult("getSurveyQuestions_Survey", callback, result);
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
query = "vaultcrm:queryObject(survey_question__v),fields(id),where(WHERE survey__v='" + survey + "'),sort(order__v,asc),com_veeva_clm_surveyQuestions(result)";
|
|
197
|
+
if(!com.veeva.clm.testMode)
|
|
198
|
+
com.veeva.clm.runAPIRequest(query);
|
|
199
|
+
else
|
|
200
|
+
com_veeva_clm_surveyQuestions(com.veeva.clm.testResult.common);
|
|
201
|
+
|
|
202
|
+
},
|
|
203
|
+
|
|
204
|
+
// 2
|
|
205
|
+
// Returns an array of record IDs of all Questions Responses (question_response__v object) for a specific Survey
|
|
206
|
+
// Target (survey_target__v). Results are returned in ascending order based on the order__v field on question_response__v.
|
|
207
|
+
// surveytarget - specifies the record id of the Survey Target to get all related Question Responses from
|
|
208
|
+
// callback - call back function which will be used to return the information
|
|
209
|
+
getQuestionResponse_SurveyTarget: function(surveytarget, callback) {
|
|
210
|
+
ret = this.checkCallbackFunction(callback);
|
|
211
|
+
if(ret.success == false)
|
|
212
|
+
return ret;
|
|
213
|
+
|
|
214
|
+
// check arguments
|
|
215
|
+
ret = this.checkArgument("surveytarget", surveytarget);
|
|
216
|
+
if(ret.success == false) {
|
|
217
|
+
com.veeva.clm.wrapResult("getQuestionResponse_SurveyTarget", callback, ret);
|
|
218
|
+
return;
|
|
219
|
+
}
|
|
220
|
+
window["com_veeva_clm_targetResponses"] = function(result) {
|
|
221
|
+
com.veeva.clm.wrapResult("getQuestionResponse_SurveyTarget", callback, result);
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
query = "vaultcrm:queryObject(question_response__v),fields(id),where(WHERE survey_target__v='" + surveytarget + "'),sort(order__v,asc),com_veeva_clm_targetResponses(result)";
|
|
225
|
+
if(!com.veeva.clm.testMode)
|
|
226
|
+
com.veeva.clm.runAPIRequest(query);
|
|
227
|
+
else
|
|
228
|
+
com_veeva_clm_targetResponses(com.veeva.clm.testResult.common);
|
|
229
|
+
},
|
|
230
|
+
|
|
231
|
+
// 3
|
|
232
|
+
// Returns an array of record IDs of all Survey Targets (survey_target__v) for a specific account (account__v), for a
|
|
233
|
+
// specific Survey (survey__v)
|
|
234
|
+
// account - specifies the record id of the account__v to get all related Survey Targets from
|
|
235
|
+
// survey - specifies the record id of the Survey to get all related Survey Targets from. Can be made optional by putting in "".
|
|
236
|
+
// callback - call back function which will be used to return the information
|
|
237
|
+
getSurveyTarget_Account: function(account, survey, callback) {
|
|
238
|
+
ret = this.checkCallbackFunction(callback);
|
|
239
|
+
if(ret.success == false)
|
|
240
|
+
return ret;
|
|
241
|
+
|
|
242
|
+
// check arguments
|
|
243
|
+
ret = this.checkArgument("account", account);
|
|
244
|
+
if(ret.success == false) {
|
|
245
|
+
com.veeva.clm.wrapResult("getSurveyTarget_Account", callback, ret);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
window["com_veeva_clm_accountSurveyTargets"] = function(result) {
|
|
250
|
+
com.veeva.clm.wrapResult("getSurveyTarget_Account", callback, result);
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
query = null;
|
|
254
|
+
if(survey == null || survey == "") {
|
|
255
|
+
query = "vaultcrm:queryObject(survey_target__v),fields(id),where(WHERE account__v='" + account + "'),com_veeva_clm_accountSurveyTargets(result)";
|
|
256
|
+
} else {
|
|
257
|
+
query = "vaultcrm:queryObject(survey_target__v),fields(id),where(WHERE account__v='" + account + "' AND survey__v='" + survey + "'),com_veeva_clm_accountSurveyTargets(result)";
|
|
258
|
+
}
|
|
259
|
+
if(!com.veeva.clm.testMode)
|
|
260
|
+
com.veeva.clm.runAPIRequest(query);
|
|
261
|
+
else
|
|
262
|
+
com_veeva_clm_accountSurveyTargets(com.veeva.clm.testResult.common);
|
|
263
|
+
},
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
/////////////////////// Order Management ///////////////////////
|
|
267
|
+
|
|
268
|
+
// * Campaign and Contract based Pricing Rules are not supported by the JavaScript Library for CLM Order Management functions"
|
|
269
|
+
// 1
|
|
270
|
+
// Returns an array of record IDs of all products (product__v) of type Order that have valid list prices
|
|
271
|
+
// Valid list price = Pricing Rule (pricing_rule__v) of record type List Price (list_price_rule__v) where current date is
|
|
272
|
+
// between Start Date (start_date__v) and End Date (end_date__v)
|
|
273
|
+
// callback - call back function which will be used to return the information
|
|
274
|
+
// account/account group - specifies the record id of an account__v or the matching text for the account_group__v. Can be made optional
|
|
275
|
+
// by putting in "". When utilized, returns an array of record IDs of all products (product__v) of type Order
|
|
276
|
+
// that have valid list price records which specify the account__v or account_group__v.
|
|
277
|
+
getProduct_OrderActive_Account: function(accountOrAccountGroup, callback) {
|
|
278
|
+
var orderProducts;
|
|
279
|
+
var ret = this.checkCallbackFunction(callback);
|
|
280
|
+
if(ret.success == false)
|
|
281
|
+
return ret;
|
|
282
|
+
|
|
283
|
+
// c, product
|
|
284
|
+
window["com_veeva_clm_ordersWithListPrice"] = function(result) {
|
|
285
|
+
result = com.veeva.clm.formatResult(result);
|
|
286
|
+
if(result.success) {
|
|
287
|
+
orderIds = [];
|
|
288
|
+
if(result.pricing_rule__v && result.pricing_rule__v.length > 0) {
|
|
289
|
+
for(i = 0; i < result.pricing_rule__v.length; i++) {
|
|
290
|
+
orderIds.push(result.pricing_rule__v[i].product__v);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
ret.success = true;
|
|
295
|
+
ret.product__v = orderIds;
|
|
296
|
+
com.veeva.clm.wrapResult("getProduct_OrderActive_Account", callback, ret);
|
|
297
|
+
} else {
|
|
298
|
+
com.veeva.clm.wrapResult("getProduct_OrderActive_Account", callback, result);
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
|
|
302
|
+
// b, got record type id
|
|
303
|
+
window["com_veeva_clm_listPriceTypeId"] = function(result) {
|
|
304
|
+
result = com.veeva.clm.formatResult(result);
|
|
305
|
+
if(result.success && result.object_type__v && result.object_type__v.length > 0) {
|
|
306
|
+
listPriceObjectTypeId = result.object_type__v[0].id;
|
|
307
|
+
|
|
308
|
+
// c, fetch product which has <list price> pricing rules
|
|
309
|
+
var ids = [];
|
|
310
|
+
for(i = 0; i < orderProducts.length; i++) {
|
|
311
|
+
ids.push(orderProducts[i].id);
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
dateString = com.veeva.clm.getCurrentDate();
|
|
315
|
+
|
|
316
|
+
query = null;
|
|
317
|
+
if(accountOrAccountGroup == null || accountOrAccountGroup == "") {
|
|
318
|
+
query = "vaultcrm:queryObject(pricing_rule__v),fields(id,product__v),where(WHERE object_type__v='" + listPriceObjectTypeId + "' AND start_date__v <= '" + dateString
|
|
319
|
+
+ "' AND end_date__v >= '" + dateString + "' AND product__v CONTAINS " + com.veeva.clm.joinStringArrayForContains(ids) + "), com_veeva_clm_ordersWithListPrice(result)";
|
|
320
|
+
} else {
|
|
321
|
+
query = "vaultcrm:queryObject(pricing_rule__v),fields(id,product__v),where(WHERE object_type__v='" + listPriceObjectTypeId + "' AND (account__v='" + accountOrAccountGroup
|
|
322
|
+
+ "' OR account_group__v = '" + accountOrAccountGroup + "') AND start_date__v <='" + dateString + "' AND end_date__v >= '" + dateString
|
|
323
|
+
+ "' AND product__v CONTAINS " + com.veeva.clm.joinStringArrayForContains(ids) + "), com_veeva_clm_ordersWithListPrice(result)";
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
if(!com.veeva.clm.testMode) {
|
|
327
|
+
com.veeva.clm.runAPIRequest(query);
|
|
328
|
+
} else {
|
|
329
|
+
com_veeva_clm_ordersWithListPrice(testResult.listPrices)
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
} else {
|
|
334
|
+
com.veeva.clm.wrapResult("getProduct_OrderActive_Account", callback, result);
|
|
335
|
+
}
|
|
336
|
+
};
|
|
337
|
+
|
|
338
|
+
// a, get order products
|
|
339
|
+
this.getProduct_MySetup("order__v", function(result) {
|
|
340
|
+
// got the list order products,
|
|
341
|
+
if(result.success) {
|
|
342
|
+
|
|
343
|
+
orderProducts = result.product__v;
|
|
344
|
+
if(orderProducts && orderProducts.length > 0) {
|
|
345
|
+
// b, find out List Price record type id
|
|
346
|
+
objectTypeQuery = "vaultcrm:queryObject(object_type__v),fields(id),where(WHERE object_name__v='pricing_rule__v' AND api_name__v='list_price_rule__v'),com_veeva_clm_listPriceTypeId(result)";
|
|
347
|
+
if(!com.veeva.clm.testMode)
|
|
348
|
+
com.veeva.clm.runAPIRequest(objectTypeQuery);
|
|
349
|
+
else
|
|
350
|
+
com_veeva_clm_listPriceTypeId(testResult.listPriceObjectType);
|
|
351
|
+
} else {
|
|
352
|
+
ret.success = true;
|
|
353
|
+
ret.product__v = [];
|
|
354
|
+
com.veeva.clm.wrapResult("getProduct_OrderActive_Account", callback, ret);
|
|
355
|
+
return;
|
|
356
|
+
}
|
|
357
|
+
} else {
|
|
358
|
+
// ERROR when geting Product of order type.
|
|
359
|
+
com.veeva.clm.wrapResult("getProduct_OrderActive_Account", callback, result);
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
|
|
363
|
+
},
|
|
364
|
+
|
|
365
|
+
// 2
|
|
366
|
+
// Returns an array of record IDs of all products (product__v) of type Kit Component (product_type__v field) who have
|
|
367
|
+
// parent product (parent_product__v) = product
|
|
368
|
+
// product - specifies the record id of the product of which to get all related Kit Components from
|
|
369
|
+
// callback - call back function which will be used to return the information
|
|
370
|
+
getProduct_KitComponents: function(product, callback) {
|
|
371
|
+
ret = this.checkCallbackFunction(callback);
|
|
372
|
+
if(ret.success == false)
|
|
373
|
+
return ret;
|
|
374
|
+
|
|
375
|
+
// check arguments
|
|
376
|
+
ret = this.checkArgument("product", product);
|
|
377
|
+
if(ret.success == false) {
|
|
378
|
+
com.veeva.clm.wrapResult("getProduct_KitComponents", callback, ret);
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
window["com_veeva_clm_childKitItems"] = function(result) {
|
|
382
|
+
com.veeva.clm.wrapResult("getProduct_KitComponents", callback, result);
|
|
383
|
+
};
|
|
384
|
+
|
|
385
|
+
|
|
386
|
+
query = "vaultcrm:queryObject(product__v),fields(id),where(WHERE product_type__v='kit_item__v' AND parent_product__v='" + product + "'),com_veeva_clm_childKitItems(result)";
|
|
387
|
+
if(!com.veeva.clm.testMode)
|
|
388
|
+
com.veeva.clm.runAPIRequest(query);
|
|
389
|
+
else
|
|
390
|
+
com_veeva_clm_childKitItems(com.veeva.clm.testResult.common);
|
|
391
|
+
},
|
|
392
|
+
|
|
393
|
+
// 3
|
|
394
|
+
// Returns an array of record IDs of Product Groups (product_group__v) that the specified product (product__v) is part of
|
|
395
|
+
// product - specifies the record id of the product of which to get all related Product Groups from
|
|
396
|
+
// callback - call back function which will be used to return the information
|
|
397
|
+
getProductGroup_Product: function(product, callback) {
|
|
398
|
+
ret = this.checkCallbackFunction(callback);
|
|
399
|
+
if(ret.success == false)
|
|
400
|
+
return ret;
|
|
401
|
+
|
|
402
|
+
// check arguments
|
|
403
|
+
ret = this.checkArgument("product", product);
|
|
404
|
+
if(ret.success == false) {
|
|
405
|
+
com.veeva.clm.wrapResult("getProductGroup_Product", callback, ret);
|
|
406
|
+
return;
|
|
407
|
+
}
|
|
408
|
+
window["com_veeva_clm_productProductGroups"] = function(result) {
|
|
409
|
+
result = com.veeva.clm.formatResult(result);
|
|
410
|
+
var ret = {};
|
|
411
|
+
if(result != null && result.success) {
|
|
412
|
+
var rows = result.product_group__v;
|
|
413
|
+
var groupIds = [];
|
|
414
|
+
if(rows && rows.length > 0) {
|
|
415
|
+
for(i = 0; i < rows.length; i++) {
|
|
416
|
+
groupIds.push(rows[i].product_catalog__v);
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
|
|
420
|
+
ret.success = true;
|
|
421
|
+
ret.product__v = groupIds;
|
|
422
|
+
|
|
423
|
+
com.veeva.clm.wrapResult("getProductGroup_Product", callback, ret);
|
|
424
|
+
} else if(result != null) {
|
|
425
|
+
com.veeva.clm.wrapResult("getProductGroup_Product", callback, result);
|
|
426
|
+
} else {
|
|
427
|
+
// is not expected from low-level API
|
|
428
|
+
}
|
|
429
|
+
};
|
|
430
|
+
|
|
431
|
+
|
|
432
|
+
query = "vaultcrm:queryObject(product_group__v),fields(id,product_catalog__v),where(WHERE product__v='" + product + "'),com_veeva_clm_productProductGroups(result)";
|
|
433
|
+
if(!com.veeva.clm.testMode)
|
|
434
|
+
com.veeva.clm.runAPIRequest(query);
|
|
435
|
+
else
|
|
436
|
+
com_veeva_clm_productProductGroups(com.veeva.clm.testResult.common);
|
|
437
|
+
},
|
|
438
|
+
|
|
439
|
+
|
|
440
|
+
// 4
|
|
441
|
+
// Returns an array of record IDs of the last 10 Orders (order__v) for a particular account (account__v)
|
|
442
|
+
// The order of last ten orders is based on the field order_date__v, descending.
|
|
443
|
+
// account - specifies the record id of the account of which to get all related orders
|
|
444
|
+
// callback - call back function which will be used to return the information
|
|
445
|
+
getLastTenOrders_Account: function(account, callback) {
|
|
446
|
+
ret = this.checkCallbackFunction(callback);
|
|
447
|
+
if(ret.success == false)
|
|
448
|
+
return ret;
|
|
449
|
+
|
|
450
|
+
// check arguments
|
|
451
|
+
ret = this.checkArgument("account", account);
|
|
452
|
+
if(ret.success == false) {
|
|
453
|
+
com.veeva.clm.wrapResult("getLastTenOrders_Account", callback, ret);
|
|
454
|
+
return;
|
|
455
|
+
}
|
|
456
|
+
|
|
457
|
+
window["com_veeva_clm_accountLastTenOrders"] = function(result) {
|
|
458
|
+
com.veeva.clm.wrapResult("getLastTenOrders_Account", callback, result);
|
|
459
|
+
};
|
|
460
|
+
|
|
461
|
+
|
|
462
|
+
query = "vaultcrm:queryObject(order__v),fields(id),where(WHERE account__v='" + account + "'),sort(order_date__v,desc),limit(10),com_veeva_clm_accountLastTenOrders(result)";
|
|
463
|
+
if(!com.veeva.clm.testMode)
|
|
464
|
+
com.veeva.clm.runAPIRequest(query);
|
|
465
|
+
else
|
|
466
|
+
com_veeva_clm_accountLastTenOrders(com.veeva.clm.testResult.common);
|
|
467
|
+
},
|
|
468
|
+
|
|
469
|
+
// 5
|
|
470
|
+
// Returns an array of record IDs of all Order Lines (order_line__v) for a particular order (order__v)
|
|
471
|
+
// order - specifies the record id of the order of which to get all related order lines
|
|
472
|
+
// callback - call back function which will be used to return the information
|
|
473
|
+
getOrderLines_Order: function(order, callback) {
|
|
474
|
+
ret = this.checkCallbackFunction(callback);
|
|
475
|
+
if(ret.success == false)
|
|
476
|
+
return ret;
|
|
477
|
+
|
|
478
|
+
// check arguments
|
|
479
|
+
ret = this.checkArgument("order", order);
|
|
480
|
+
if(ret.success == false) {
|
|
481
|
+
com.veeva.clm.wrapResult("getOrderLines_Order", callback, ret);
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
484
|
+
window["com_veeva_clm_orderLines"] = function(result) {
|
|
485
|
+
com.veeva.clm.wrapResult("getOrderLines_Order", callback, result);
|
|
486
|
+
};
|
|
487
|
+
|
|
488
|
+
|
|
489
|
+
query = "vaultcrm:queryObject(order_line__v),fields(id),where(WHERE order__v='" + order + "'),com_veeva_clm_orderLines(result)";
|
|
490
|
+
if(!com.veeva.clm.testMode)
|
|
491
|
+
com.veeva.clm.runAPIRequest(query);
|
|
492
|
+
else
|
|
493
|
+
com_veeva_clm_orderLines(com.veeva.clm.testResult.common);
|
|
494
|
+
},
|
|
495
|
+
|
|
496
|
+
// 6
|
|
497
|
+
// Requires that an account__v be specified in order for any result to be returned.
|
|
498
|
+
// Returns the record id for the currently valid List Price (pricing_rule__v) for a specific product (product__v) and account__v combination. Respects the account__v and Account Group List Price hierarchy.
|
|
499
|
+
// Valid list price = Pricing Rule (pricing_rule__v) of record type List Price (list_price_rule__v) where current date is between Start Date (start_date__v) and End Date (end_date__v)
|
|
500
|
+
// product - specifies the record id of the product of which to get the Pricing Rule for
|
|
501
|
+
// account - specifies the account__v for which to select List Prices for
|
|
502
|
+
// callback - call back function which will be used to return the information
|
|
503
|
+
getListPrice_Product_Account: function(product, account, callback) {
|
|
504
|
+
ret = this.checkCallbackFunction(callback);
|
|
505
|
+
if(ret.success == false)
|
|
506
|
+
return ret;
|
|
507
|
+
|
|
508
|
+
// check arguments
|
|
509
|
+
ret = this.checkArgument("product", product);
|
|
510
|
+
if(ret.success == false) {
|
|
511
|
+
com.veeva.clm.wrapResult("getListPrice_Product_Account", callback, ret);
|
|
512
|
+
return;
|
|
513
|
+
}
|
|
514
|
+
ret = this.checkArgument("account", account);
|
|
515
|
+
if(ret.success == false) {
|
|
516
|
+
com.veeva.clm.wrapResult("getListPrice_Product_Account", callback, ret);
|
|
517
|
+
return;
|
|
518
|
+
}
|
|
519
|
+
|
|
520
|
+
window["com_veeva_clm_productDefaultPricingRules"] = function(result) {
|
|
521
|
+
com.veeva.clm.wrapResult("getListPrice_Product_Account", callback, result);
|
|
522
|
+
};
|
|
523
|
+
|
|
524
|
+
window["com_veeva_clm_get_productDefaultPricingRules"] = function() {
|
|
525
|
+
|
|
526
|
+
dateString = com.veeva.clm.getCurrentDate();
|
|
527
|
+
groupQuery = "vaultcrm:queryObject(pricing_rule__v),fields(id),where(WHERE object_type__v='" + listPriceObjectTypeId + "' AND product__v = '" + product + "'"
|
|
528
|
+
+ " AND account_group__v='' AND account__v=''"
|
|
529
|
+
+ " AND start_date__v <= '" + dateString + "' AND end_date__v >= '" + dateString + "'), com_veeva_clm_productDefaultPricingRules(result)";
|
|
530
|
+
if(!com.veeva.clm.testMode)
|
|
531
|
+
com.veeva.clm.runAPIRequest(groupQuery);
|
|
532
|
+
else {
|
|
533
|
+
// TODO
|
|
534
|
+
com_veeva_clm_productDefaultPricingRules(com.veeva.clm.testResult.listPrices);
|
|
535
|
+
}
|
|
536
|
+
};
|
|
537
|
+
|
|
538
|
+
window["com_veeva_clm_productAccountGroupPricingRules"] = function(result) {
|
|
539
|
+
result = com.veeva.clm.formatResult(result);
|
|
540
|
+
if(result.success && result.pricing_rule__v.length == 0) {
|
|
541
|
+
// try account group
|
|
542
|
+
com_veeva_clm_get_productDefaultPricingRules();
|
|
543
|
+
}
|
|
544
|
+
else
|
|
545
|
+
com.veeva.clm.wrapResult("getListPrice_Product_Account", callback, result);
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
// 4 pricing rule for account group
|
|
549
|
+
window['com_veeva_clm_accountGroup'] = function(result) {
|
|
550
|
+
result = com.veeva.clm.formatResult(result);
|
|
551
|
+
if(result.success) {
|
|
552
|
+
accountGroup = result.Account.account_group__v;
|
|
553
|
+
if(accountGroup != undefined && accountGroup != "") {
|
|
554
|
+
dateString = com.veeva.clm.getCurrentDate();
|
|
555
|
+
groupQuery = "vaultcrm:queryObject(pricing_rule__v),fields(id),where(WHERE object_type__v='" + listPriceObjectTypeId + "' AND product__v = '" + product + "'"
|
|
556
|
+
+ " AND account_group__v='" + accountGroup + "'"
|
|
557
|
+
+ " AND start_date__v <= '" + dateString + "' AND end_date__v >= '" + dateString + "'), com_veeva_clm_productAccountGroupPricingRules(result)";
|
|
558
|
+
if(!com.veeva.clm.testMode)
|
|
559
|
+
com.veeva.clm.runAPIRequest(groupQuery);
|
|
560
|
+
else {
|
|
561
|
+
// TODO
|
|
562
|
+
com_veeva_clm_productAccountGroupPricingRules(com.veeva.clm.testResult.listPrices);
|
|
563
|
+
}
|
|
564
|
+
} else {
|
|
565
|
+
com_veeva_clm_get_productDefaultPricingRules();
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
else {
|
|
569
|
+
com.veeva.clm.wrapResult("getListPrice_Product_Account", callback, result);
|
|
570
|
+
}
|
|
571
|
+
};
|
|
572
|
+
|
|
573
|
+
// 3 account group
|
|
574
|
+
window["com_veeva_clm_productAccountPricingRules"] = function(result) {
|
|
575
|
+
result = com.veeva.clm.formatResult(result);
|
|
576
|
+
if(result.success && result.pricing_rule__v.length == 0) {
|
|
577
|
+
// try account group
|
|
578
|
+
com.veeva.clm.getDataForObject("Account", account, "account_group__v", com_veeva_clm_accountGroup);
|
|
579
|
+
}
|
|
580
|
+
else
|
|
581
|
+
com.veeva.clm.wrapResult("getListPrice_Product_Account", callback, result);
|
|
582
|
+
};
|
|
583
|
+
|
|
584
|
+
// 2
|
|
585
|
+
window["com_veeva_clm_listPriceTypeId_getListPrice_Product_Account"] = function(result) {
|
|
586
|
+
result = com.veeva.clm.formatResult(result);
|
|
587
|
+
if(result.success && result.object_type__v && result.object_type__v.length > 0) {
|
|
588
|
+
listPriceObjectTypeId = result.object_type__v[0].id;
|
|
589
|
+
|
|
590
|
+
dateString = com.veeva.clm.getCurrentDate();
|
|
591
|
+
query = "vaultcrm:queryObject(pricing_rule__v),fields(id),where(WHERE object_type__v='" + listPriceObjectTypeId + "' AND product__v = '" + product + "'"
|
|
592
|
+
+ " AND account__v='" + account + "'"
|
|
593
|
+
+ " AND start_date__v <= '" + dateString + "' AND end_date__v >= '" + dateString + "'), com_veeva_clm_productAccountPricingRules(result)";
|
|
594
|
+
|
|
595
|
+
if(!com.veeva.clm.testMode)
|
|
596
|
+
com.veeva.clm.runAPIRequest(query);
|
|
597
|
+
else
|
|
598
|
+
com_veeva_clm_productAccountPricingRules(com.veeva.clm.testResult.listPrices);
|
|
599
|
+
} else {
|
|
600
|
+
com.veeva.clm.wrapResult("getListPrice_Product_Account", callback, result);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
};
|
|
604
|
+
|
|
605
|
+
// 1, fetch list price record type first
|
|
606
|
+
objectTypeQuery = "vaultcrm:queryObject(object_type__v),fields(id),where(WHERE object_name__v='pricing_rule__v' AND api_name__v='list_price_rule__v'),com_veeva_clm_listPriceTypeId_getListPrice_Product_Account(result)";
|
|
607
|
+
if(!com.veeva.clm.testMode)
|
|
608
|
+
com.veeva.clm.runAPIRequest(objectTypeQuery);
|
|
609
|
+
else
|
|
610
|
+
com_veeva_clm_listPriceTypeId_getListPrice_Product_Account(testResult.listPriceObjectType);
|
|
611
|
+
|
|
612
|
+
},
|
|
613
|
+
|
|
614
|
+
/////////////////////// Approved Email ///////////////////////
|
|
615
|
+
|
|
616
|
+
// Returns the record id(s) for the Approved Document which matches the values specified and approved_document_status__v = approved__v
|
|
617
|
+
// Gets the approved document by querying all products of type Detail Topic or Detail and compares against
|
|
618
|
+
// the query of any approved documents with the passed in vault_id and
|
|
619
|
+
// document_num. If there are multiple documents with these same ids, an error is thrown.
|
|
620
|
+
// vault_id - specifies the Vault id of the Approved Document to retrieve. (vault_instance_id__v on approved_document__v)
|
|
621
|
+
// document_num - specifies the document number of the Approved Document to retrieve. (vault_document_id__v on approved_document__v)
|
|
622
|
+
// callback - call back function which will be used to return the information
|
|
623
|
+
getApprovedDocument: function(vault_id, document_num, callback) {
|
|
624
|
+
var topicProducts;
|
|
625
|
+
var detailProducts;
|
|
626
|
+
var detailGroupProducts;
|
|
627
|
+
var productGroups;
|
|
628
|
+
|
|
629
|
+
// check callback parameter
|
|
630
|
+
ret = this.checkCallbackFunction(callback);
|
|
631
|
+
if(ret.success == false)
|
|
632
|
+
return ret;
|
|
633
|
+
|
|
634
|
+
// check arguments
|
|
635
|
+
ret = this.checkArgument("vault_id", vault_id);
|
|
636
|
+
if(ret.success == false) {
|
|
637
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
638
|
+
return;
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
ret = this.checkArgument("document_num", document_num);
|
|
642
|
+
if(ret.success == false) {
|
|
643
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
644
|
+
return;
|
|
645
|
+
}
|
|
646
|
+
|
|
647
|
+
// check version
|
|
648
|
+
this.getAppVersion(function(result) {
|
|
649
|
+
var isFeatureMultiProductSupported = false;
|
|
650
|
+
if (result.success) {
|
|
651
|
+
var version = result.Version;
|
|
652
|
+
// compare the version
|
|
653
|
+
var n = FEATURE_MULTI_PRODUCT_MIN_VERSION.localeCompare(version);
|
|
654
|
+
// returns -1 if the min version is before the current version
|
|
655
|
+
// returns 0 if the two versions are equal
|
|
656
|
+
// returns 1 if the min version is after the current version
|
|
657
|
+
if (n < 1) {
|
|
658
|
+
isFeatureMultiProductSupported = true;
|
|
659
|
+
//If the current version is compatible, run the request vaultcrm:getApprovedDocument to get the document
|
|
660
|
+
//Otherwise, we just run existing js logic to return the document
|
|
661
|
+
window["com_veeva_clm_approvedDocument"] = function(result) {
|
|
662
|
+
result = com.veeva.clm.formatResult(result);
|
|
663
|
+
if (result.success && result.ApprovedDocumentId) {
|
|
664
|
+
var ret = {};
|
|
665
|
+
ret.approved_document__v = {};
|
|
666
|
+
ret.approved_document__v.id = result.ApprovedDocumentId;
|
|
667
|
+
ret.success = true;
|
|
668
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
669
|
+
return;
|
|
670
|
+
} else {
|
|
671
|
+
var ret = {};
|
|
672
|
+
ret.success = false;
|
|
673
|
+
if(result.code != undefined){
|
|
674
|
+
ret.code = result.code;
|
|
675
|
+
}
|
|
676
|
+
if(result.message != undefined){
|
|
677
|
+
ret.message = result.message;
|
|
678
|
+
}
|
|
679
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
680
|
+
return;
|
|
681
|
+
}
|
|
682
|
+
}
|
|
683
|
+
|
|
684
|
+
query = "vaultcrm:getApprovedDocument(" + vault_id + "," + document_num + "),com_veeva_clm_approvedDocument(result)";
|
|
685
|
+
if (!com.veeva.clm.testMode)
|
|
686
|
+
com.veeva.clm.runAPIRequest(query);
|
|
687
|
+
else
|
|
688
|
+
com_veeva_clm_appVersion(com.veeva.clm.testResult.common);
|
|
689
|
+
}
|
|
690
|
+
}
|
|
691
|
+
|
|
692
|
+
if( isFeatureMultiProductSupported == false) {
|
|
693
|
+
// existing js logic to return the document
|
|
694
|
+
// 2b Check results of Approved Document query against My Setup results
|
|
695
|
+
window["com_veeva_clm_DocumentTypeId_getDocument"] = function(result) {
|
|
696
|
+
result = com.veeva.clm.formatResult(result);
|
|
697
|
+
|
|
698
|
+
if(result.success && result.approved_document__v && result.approved_document__v.length == 1) {
|
|
699
|
+
var productsWithDetailGroups;
|
|
700
|
+
|
|
701
|
+
//If we have access to detail groups, align products with detail groups
|
|
702
|
+
if(detailGroupProducts != undefined && productGroups != undefined && productGroups.length > 0) {
|
|
703
|
+
productsWithDetailGroups = [];
|
|
704
|
+
var groupCount = 0;
|
|
705
|
+
for(var i = 0; i < detailGroupProducts.length; i++) {
|
|
706
|
+
for(var j = 0; j < productGroups.length; j++) {
|
|
707
|
+
//If the detail group product id matches the product group's Product Catalog id
|
|
708
|
+
//AND it is the product we are looking for, add it
|
|
709
|
+
if(detailGroupProducts[i].id != undefined
|
|
710
|
+
&& productGroups[j].product_catalog__v != undefined
|
|
711
|
+
&& productGroups[j].product__v != undefined
|
|
712
|
+
&& detailGroupProducts[i].id == productGroups[j].product_catalog__v
|
|
713
|
+
&& result.approved_document__v[0].product__v == productGroups[j].product__v) {
|
|
714
|
+
productsWithDetailGroups[groupCount] = {};
|
|
715
|
+
productsWithDetailGroups[groupCount].id = {};
|
|
716
|
+
productsWithDetailGroups[groupCount].detail_group__v = {};
|
|
717
|
+
productsWithDetailGroups[groupCount].id = productGroups[j].product__v;
|
|
718
|
+
productsWithDetailGroups[groupCount].detail_group__v = detailGroupProducts[i].id;
|
|
719
|
+
groupCount++;
|
|
720
|
+
break;
|
|
721
|
+
}
|
|
722
|
+
}
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
|
|
726
|
+
if(topicProducts && topicProducts.length > 0) {
|
|
727
|
+
//Check against the detail topics for a valid product match
|
|
728
|
+
for(var j = 0; j < topicProducts.length; j++) {
|
|
729
|
+
if(result.approved_document__v[0].product__v === topicProducts[j].id) {
|
|
730
|
+
//If we have product groups that match our current product, run through them
|
|
731
|
+
//Otherwise, we just have a product w/o detail groups, so return the document
|
|
732
|
+
if(productsWithDetailGroups != undefined && productsWithDetailGroups.length > 0) {
|
|
733
|
+
for(var i = 0; i < productsWithDetailGroups.length; i++) {
|
|
734
|
+
if(result.approved_document__v[0].detail_group__v != undefined
|
|
735
|
+
&& result.approved_document__v[0].product__v == productsWithDetailGroups[i].id
|
|
736
|
+
&& result.approved_document__v[0].detail_group__v == productsWithDetailGroups[i].detail_group__v) {
|
|
737
|
+
var ret = {};
|
|
738
|
+
ret.approved_document__v = {};
|
|
739
|
+
ret.approved_document__v.id = result.approved_document__v[0].id;
|
|
740
|
+
ret.success = true;
|
|
741
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
else {
|
|
747
|
+
var ret = {};
|
|
748
|
+
ret.approved_document__v = {};
|
|
749
|
+
ret.approved_document__v.id = result.approved_document__v[0].id;
|
|
750
|
+
ret.success = true;
|
|
751
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
if(detailProducts && detailProducts.length > 0) {
|
|
758
|
+
//Check against the details for a valid product match
|
|
759
|
+
for(var k = 0; k < detailProducts.length; k++) {
|
|
760
|
+
if(result.approved_document__v[0].product__v === detailProducts[k].id) {
|
|
761
|
+
//If we have product groups that match our current product, run through them
|
|
762
|
+
//Otherwise, we just have a product w/o detail groups, so return the document
|
|
763
|
+
if(productsWithDetailGroups != undefined && productsWithDetailGroups.length > 0) {
|
|
764
|
+
for(var i = 0; i < productsWithDetailGroups.length; i++) {
|
|
765
|
+
if(result.approved_document__v[0].detail_group__v != undefined
|
|
766
|
+
&& result.approved_document__v[0].product__v == productsWithDetailGroups[i].id
|
|
767
|
+
&& result.approved_document__v[0].detail_group__v == productsWithDetailGroups[i].detail_group__v) {
|
|
768
|
+
var ret = {};
|
|
769
|
+
ret.approved_document__v = {};
|
|
770
|
+
ret.approved_document__v.id = result.approved_document__v[0].id;
|
|
771
|
+
ret.success = true;
|
|
772
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
773
|
+
return;
|
|
774
|
+
}
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
else {
|
|
778
|
+
var ret = {};
|
|
779
|
+
ret.approved_document__v = {};
|
|
780
|
+
ret.approved_document__v.id = result.approved_document__v[0].id;
|
|
781
|
+
ret.success = true;
|
|
782
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
783
|
+
return;
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
}
|
|
788
|
+
//Found no match, return empty object
|
|
789
|
+
var ret = {};
|
|
790
|
+
ret.success = true;
|
|
791
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
792
|
+
}
|
|
793
|
+
//Query success, but we found more than one doc with the same vault id and doc num, so return empty
|
|
794
|
+
else if(result.success && result.approved_document__v && result.approved_document__v.length > 1) {
|
|
795
|
+
var ret = {};
|
|
796
|
+
ret.success = true;
|
|
797
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
798
|
+
}
|
|
799
|
+
else {
|
|
800
|
+
if(result.code == 1021) {
|
|
801
|
+
if(result.message.indexOf("detail_group__v") >= 0) {
|
|
802
|
+
approvedDocumentQuery = "vaultcrm:queryObject(approved_document__v),fields(id,product__v),where(WHERE vault_instance_id__v='" + vault_id
|
|
803
|
+
+ "' AND vault_document_id__v='" + document_num + "' AND approved_document_status__v='approved__v'),com_veeva_clm_DocumentTypeId_getDocument(result)";
|
|
804
|
+
|
|
805
|
+
if(!com.veeva.clm.testMode)
|
|
806
|
+
com.veeva.clm.runAPIRequest(approvedDocumentQuery);
|
|
807
|
+
else
|
|
808
|
+
com_veeva_clm_DocumentTypeId_getDocument(testResult.approvedDocumentWithId2);
|
|
809
|
+
}
|
|
810
|
+
return;
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
//Didn't find anything matching, return empty object with success true (not just an empty query object)
|
|
814
|
+
var ret = {};
|
|
815
|
+
ret.success = true;
|
|
816
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, ret);
|
|
817
|
+
}
|
|
818
|
+
};
|
|
819
|
+
|
|
820
|
+
// 2a - If we have detail groups, get the product groups so we can align products to detail groups
|
|
821
|
+
window["com_veeva_clm_getProductGroups"] = function(result) {
|
|
822
|
+
result = com.veeva.clm.formatResult(result);
|
|
823
|
+
|
|
824
|
+
if(result.success) {
|
|
825
|
+
productGroups = result.product_group__v;
|
|
826
|
+
|
|
827
|
+
approvedDocumentQuery = "vaultcrm:queryObject(approved_document__v),fields(id,product__v,detail_group__v),where(WHERE vault_instance_id__v='" + vault_id + "' AND vault_document_id__v='" + document_num + "' AND approved_document_status__v='approved__v'),com_veeva_clm_DocumentTypeId_getDocument(result)";
|
|
828
|
+
|
|
829
|
+
if(!com.veeva.clm.testMode)
|
|
830
|
+
com.veeva.clm.runAPIRequest(approvedDocumentQuery);
|
|
831
|
+
else
|
|
832
|
+
com_veeva_clm_DocumentTypeId_getDocument(testResult.approvedDocumentWithId);
|
|
833
|
+
}
|
|
834
|
+
else {
|
|
835
|
+
if(result.code == 1011) {
|
|
836
|
+
//No access to Product Groups specifically, so just use Products
|
|
837
|
+
if(result.message.indexOf("product_group__v") >= 0) {
|
|
838
|
+
approvedDocumentQuery = "vaultcrm:queryObject(approved_document__v),fields(id,product__v),where(WHERE vault_instance_id__v='" + vault_id + "' AND vault_document_id__v='" + document_num + "' AND approved_document_status__v='approved__v'),com_veeva_clm_DocumentTypeId_getDocument(result)";
|
|
839
|
+
|
|
840
|
+
if(!com.veeva.clm.testMode)
|
|
841
|
+
com.veeva.clm.runAPIRequest(approvedDocumentQuery);
|
|
842
|
+
else
|
|
843
|
+
com_veeva_clm_DocumentTypeId_getDocument(testResult.approvedDocumentWithId2);
|
|
844
|
+
}
|
|
845
|
+
return;
|
|
846
|
+
}
|
|
847
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, result);
|
|
848
|
+
}
|
|
849
|
+
};
|
|
850
|
+
|
|
851
|
+
// 1, get detail topic products first
|
|
852
|
+
com.veeva.clm.getProduct_MySetup("detail_topic__v", function(result) {
|
|
853
|
+
result = com.veeva.clm.formatResult(result);
|
|
854
|
+
|
|
855
|
+
// got a list of detail topic products
|
|
856
|
+
if(result.success) {
|
|
857
|
+
topicProducts = result.product__v;
|
|
858
|
+
|
|
859
|
+
com.veeva.clm.getProduct_MySetup("detail__v", function(result) {
|
|
860
|
+
if(result.success) {
|
|
861
|
+
detailProducts = result.product__v;
|
|
862
|
+
|
|
863
|
+
com.veeva.clm.getProduct_MySetup("detail_group__v", function(result) {
|
|
864
|
+
if(result.success) {
|
|
865
|
+
detailGroupProducts = result.product__v;
|
|
866
|
+
|
|
867
|
+
var detailGroupIDs = [];
|
|
868
|
+
for(var i = 0; i < detailGroupProducts.length; i++) {
|
|
869
|
+
detailGroupIDs[i] = detailGroupProducts[i].id;
|
|
870
|
+
}
|
|
871
|
+
|
|
872
|
+
var groupArray = com.veeva.clm.joinStringArrayForContains(detailGroupIDs);
|
|
873
|
+
if(groupArray == "") {
|
|
874
|
+
groupArray = "{}";
|
|
875
|
+
}
|
|
876
|
+
|
|
877
|
+
//Pass in our detail groups and find any products associated with them
|
|
878
|
+
query = "vaultcrm:queryObject(product_group__v),fields(id,product__v,product_catalog__v),where(WHERE product_catalog__v CONTAINS " + groupArray + "),com_veeva_clm_getProductGroups(result)";
|
|
879
|
+
if(!com.veeva.clm.testMode)
|
|
880
|
+
com.veeva.clm.runAPIRequest(query);
|
|
881
|
+
else
|
|
882
|
+
com_veeva_clm_getProductGroups(com.veeva.clm.testResult.productGroups);
|
|
883
|
+
|
|
884
|
+
}
|
|
885
|
+
else {
|
|
886
|
+
// ERROR when getting Product of detail group type.
|
|
887
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, result);
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
});
|
|
891
|
+
}
|
|
892
|
+
else {
|
|
893
|
+
// ERROR when getting Product of detail type.
|
|
894
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, result);
|
|
895
|
+
return;
|
|
896
|
+
}
|
|
897
|
+
});
|
|
898
|
+
} else {
|
|
899
|
+
// ERROR when getting Product of detail topic type.
|
|
900
|
+
com.veeva.clm.wrapResult("getApprovedDocument", callback, result);
|
|
901
|
+
return;
|
|
902
|
+
}
|
|
903
|
+
});
|
|
904
|
+
|
|
905
|
+
}
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
},
|
|
909
|
+
// Launches the Send Email user interface with the email template and fragments selected. An account__v must be selected.
|
|
910
|
+
// If CLM_Select_Account_Preview_Mode Veeva Setting is enabled, then Select Account dialogue is opened so the user can select an account.
|
|
911
|
+
// If the Veeva Setting is not enabled and no account__v is selected, then no action will be performed.
|
|
912
|
+
// email_template - specifies the record id of the Email Template to use
|
|
913
|
+
// email_fragments - array or string with comma separated values of record IDs of the Email fragments to use. Can be made optional by putting in ""
|
|
914
|
+
// callback - call back function which will be used to return the information
|
|
915
|
+
launchApprovedEmail: function(email_template, email_fragments, callback) {
|
|
916
|
+
// check parameter
|
|
917
|
+
|
|
918
|
+
ret = this.checkCallbackFunction(callback);
|
|
919
|
+
if(ret.success == false)
|
|
920
|
+
return ret;
|
|
921
|
+
|
|
922
|
+
// check arguments and make them empty if they don't exist
|
|
923
|
+
if(email_template == undefined || email_template == null) {
|
|
924
|
+
email_template = "";
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
//Make sure email_fragments exists
|
|
928
|
+
if(email_fragments == undefined || email_fragments == null) {
|
|
929
|
+
email_fragments = "";
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
request = null;
|
|
933
|
+
window["com_veeva_clm_launchApprovedEmail"] = function(result) {
|
|
934
|
+
result = com.veeva.clm.formatResult(result);
|
|
935
|
+
if(result.success) {
|
|
936
|
+
ret = {};
|
|
937
|
+
ret.success = true;
|
|
938
|
+
if(result.code != undefined) {
|
|
939
|
+
ret.code = result.code;
|
|
940
|
+
ret.message = result.message;
|
|
941
|
+
}
|
|
942
|
+
com.veeva.clm.wrapResult("launchApprovedEmail", callback, ret);
|
|
943
|
+
} else {
|
|
944
|
+
ret = {};
|
|
945
|
+
ret.success = false;
|
|
946
|
+
ret.code = result.code;
|
|
947
|
+
ret.message = "Request: " + request + " failed: " + result.message;
|
|
948
|
+
com.veeva.clm.wrapResult("launchApprovedEmail", callback, ret);
|
|
949
|
+
}
|
|
950
|
+
};
|
|
951
|
+
|
|
952
|
+
request = "vaultcrm:launchApprovedEmail(" + email_template + "," + email_fragments + "),callback(com_veeva_clm_launchApprovedEmail)";
|
|
953
|
+
|
|
954
|
+
if(!com.veeva.clm.testMode)
|
|
955
|
+
com.veeva.clm.runAPIRequest(request);
|
|
956
|
+
else
|
|
957
|
+
com_veeva_clm_launchApprovedEmail(com.veeva.clm.testResult.approvedEmailId);
|
|
958
|
+
|
|
959
|
+
},
|
|
960
|
+
|
|
961
|
+
/////////////////////// Functions to replace exising API calls ///////////////////////
|
|
962
|
+
|
|
963
|
+
// 1
|
|
964
|
+
// Returns the value of a field for a specific record related to the current call
|
|
965
|
+
// object - Limited to the following keywords: Account, TSF, User, Address, Call, Presentation, KeyMessage, and CallObjective.
|
|
966
|
+
// field- field api name to return a value for
|
|
967
|
+
// callback - call back function which will be used to return the information
|
|
968
|
+
getDataForCurrentObject: function(object, field, callback) {
|
|
969
|
+
ret = this.checkCallbackFunction(callback);
|
|
970
|
+
if(ret.success == false)
|
|
971
|
+
return ret;
|
|
972
|
+
|
|
973
|
+
// check arguments
|
|
974
|
+
ret = this.checkArgument("object", object);
|
|
975
|
+
if(ret.success == false) {
|
|
976
|
+
com.veeva.clm.wrapResult("getDataForCurrentObject", callback, ret);
|
|
977
|
+
return;
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
|
|
981
|
+
ret = this.checkArgument("field", field);
|
|
982
|
+
if(ret.success == false) {
|
|
983
|
+
com.veeva.clm.wrapResult("getDataForCurrentObject", callback, ret);
|
|
984
|
+
return;
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
window["com_veeva_clm_getCurrentObjectField"] = function(result) {
|
|
988
|
+
// TODO result format
|
|
989
|
+
com.veeva.clm.wrapResult("getDataForCurrentObject", callback, result);
|
|
990
|
+
}
|
|
991
|
+
|
|
992
|
+
lowerName = object.toLowerCase();
|
|
993
|
+
|
|
994
|
+
request = "vaultcrm:getDataForObjectV2(" + object + "),fieldName(" + field + "),com_veeva_clm_getCurrentObjectField(result)";
|
|
995
|
+
if(!com.veeva.clm.testMode)
|
|
996
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
997
|
+
else
|
|
998
|
+
com_veeva_clm_getCurrentObjectField(com.veeva.clm.testResult.common);
|
|
999
|
+
},
|
|
1000
|
+
|
|
1001
|
+
// 2
|
|
1002
|
+
// Returns the value of a field for a specific record
|
|
1003
|
+
// object - specifies the object api name (object keywords used in getDataForCurrentObject are not valid, except for Account and User)
|
|
1004
|
+
// record - specifies the record id.
|
|
1005
|
+
// field- field api name to return a value for
|
|
1006
|
+
// callback - call back function which will be used to return the information
|
|
1007
|
+
getDataForObject: function(object, record, field, callback) {
|
|
1008
|
+
ret = this.checkCallbackFunction(callback);
|
|
1009
|
+
if(ret.success == false)
|
|
1010
|
+
return ret;
|
|
1011
|
+
|
|
1012
|
+
// check arguments
|
|
1013
|
+
ret = this.checkArgument("object", object);
|
|
1014
|
+
if(ret.success == false) {
|
|
1015
|
+
com.veeva.clm.wrapResult("getDataForObject", callback, ret);
|
|
1016
|
+
return;
|
|
1017
|
+
}
|
|
1018
|
+
|
|
1019
|
+
|
|
1020
|
+
ret = this.checkArgument("record", record);
|
|
1021
|
+
if(ret.success == false) {
|
|
1022
|
+
com.veeva.clm.wrapResult("getDataForObject", callback, ret);
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
|
|
1026
|
+
ret = this.checkArgument("field", field);
|
|
1027
|
+
if(ret.success == false) {
|
|
1028
|
+
com.veeva.clm.wrapResult("getDataForObject", callback, ret);
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
|
|
1032
|
+
window["com_veeva_clm_getObjectField"] = function(result) {
|
|
1033
|
+
// TODO result format
|
|
1034
|
+
com.veeva.clm.wrapResult("getDataForObject", callback, result);
|
|
1035
|
+
}
|
|
1036
|
+
|
|
1037
|
+
|
|
1038
|
+
request = "vaultcrm:getDataForObjectV2(" + object + "),objId(" + record + "),fieldName(" + field + "),com_veeva_clm_getObjectField(result)";
|
|
1039
|
+
if(!com.veeva.clm.testMode)
|
|
1040
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1041
|
+
else
|
|
1042
|
+
com_veeva_clm_getObjectField(com.veeva.clm.testResult.common);
|
|
1043
|
+
|
|
1044
|
+
},
|
|
1045
|
+
|
|
1046
|
+
|
|
1047
|
+
// 3
|
|
1048
|
+
// Creates a new record for the specified object
|
|
1049
|
+
// object - specifies the object api name
|
|
1050
|
+
// values - json object with the fields and values to be written to the new record
|
|
1051
|
+
// callback - call back function which will be used to return the information
|
|
1052
|
+
// NOTE: This function returns success: true as long as the user has access to the object.
|
|
1053
|
+
// If the user does not have access to one of the fields specified, success: true is still returned, however,
|
|
1054
|
+
// and the fields the user does have access to are still updated.
|
|
1055
|
+
createRecord: function(object, values, callback) {
|
|
1056
|
+
ret = this.checkCallbackFunction(callback);
|
|
1057
|
+
if(ret.success == false)
|
|
1058
|
+
return ret;
|
|
1059
|
+
|
|
1060
|
+
// check arguments
|
|
1061
|
+
ret = this.checkArgument("object", object);
|
|
1062
|
+
if(ret.success == false) {
|
|
1063
|
+
com.veeva.clm.wrapResult("createRecord", callback, ret);
|
|
1064
|
+
return;
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
|
|
1068
|
+
ret = this.checkArgument("values", values);
|
|
1069
|
+
if(ret.success == false) {
|
|
1070
|
+
com.veeva.clm.wrapResult("createRecord", callback, ret);
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
request = com.veeva.clm.generateSaveRecordRequest(object, values, "com_veeva_clm_createRecord");
|
|
1075
|
+
window["com_veeva_clm_createRecord"] = function(result) {
|
|
1076
|
+
result = com.veeva.clm.formatResult(result);
|
|
1077
|
+
if(result.success) {
|
|
1078
|
+
ret = {};
|
|
1079
|
+
ret.success = true;
|
|
1080
|
+
ret.operation = result.operation;
|
|
1081
|
+
ret[object] = {};
|
|
1082
|
+
ret[object].id = result.objectId;
|
|
1083
|
+
if(result.code != undefined) {
|
|
1084
|
+
ret.code = result.code;
|
|
1085
|
+
ret.message = result.message;
|
|
1086
|
+
}
|
|
1087
|
+
com.veeva.clm.wrapResult("createRecord", callback, ret);
|
|
1088
|
+
} else {
|
|
1089
|
+
ret = {};
|
|
1090
|
+
ret.success = false;
|
|
1091
|
+
ret.code = 2100;
|
|
1092
|
+
ret.message = "Request: " + request + " failed: " + result.message;
|
|
1093
|
+
com.veeva.clm.wrapResult("createRecord", callback, ret);
|
|
1094
|
+
}
|
|
1095
|
+
};
|
|
1096
|
+
|
|
1097
|
+
// create record
|
|
1098
|
+
if(!com.veeva.clm.testMode)
|
|
1099
|
+
com.veeva.clm.runAPIRequest(request);
|
|
1100
|
+
else
|
|
1101
|
+
com_veeva_clm_createRecord(com.veeva.clm.testResult.common);
|
|
1102
|
+
},
|
|
1103
|
+
|
|
1104
|
+
// 4
|
|
1105
|
+
// Updates a specified record
|
|
1106
|
+
// object - specifies the object api name
|
|
1107
|
+
// record - specifies the record id to be updated
|
|
1108
|
+
// values - json object with the fields and values updated on the record
|
|
1109
|
+
// callback - call back function which will be used to return the information
|
|
1110
|
+
// NOTE: This function returns success: true as long as the user has access to the object.
|
|
1111
|
+
// If the user does not have access to one of the fields specified, success: true is still returned, however,
|
|
1112
|
+
// and the fields the user does have access to are still updated.
|
|
1113
|
+
updateRecord: function(object, record, values, callback) {
|
|
1114
|
+
ret = this.checkCallbackFunction(callback);
|
|
1115
|
+
if(ret.success == false)
|
|
1116
|
+
return ret;
|
|
1117
|
+
|
|
1118
|
+
// check arguments
|
|
1119
|
+
ret = this.checkArgument("object", object);
|
|
1120
|
+
if(ret.success == false) {
|
|
1121
|
+
com.veeva.clm.wrapResult("updateRecord", callback, ret);
|
|
1122
|
+
return;
|
|
1123
|
+
}
|
|
1124
|
+
|
|
1125
|
+
ret = this.checkArgument("record", record);
|
|
1126
|
+
if(ret.success == false) {
|
|
1127
|
+
com.veeva.clm.wrapResult("updateRecord", callback, ret);
|
|
1128
|
+
return;
|
|
1129
|
+
}
|
|
1130
|
+
|
|
1131
|
+
ret = this.checkArgument("values", values);
|
|
1132
|
+
if(ret.success == false) {
|
|
1133
|
+
com.veeva.clm.wrapResult("updateRecord", callback, ret);
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
// Id is required for updating existing record
|
|
1137
|
+
values.IdNumber = record;
|
|
1138
|
+
|
|
1139
|
+
// create record
|
|
1140
|
+
request = com.veeva.clm.generateSaveRecordRequest(object, values, "com_veeva_clm_updateRecord");
|
|
1141
|
+
|
|
1142
|
+
window["com_veeva_clm_updateRecord"] = function(result) {
|
|
1143
|
+
result = com.veeva.clm.formatResult(result);
|
|
1144
|
+
if(result.success) {
|
|
1145
|
+
ret = {};
|
|
1146
|
+
ret.success = true;
|
|
1147
|
+
ret.operation = result.operation;
|
|
1148
|
+
ret[object] = {};
|
|
1149
|
+
ret[object].id = result.objectId;
|
|
1150
|
+
if(result.code != undefined) {
|
|
1151
|
+
ret.code = result.code;
|
|
1152
|
+
ret.message = result.message;
|
|
1153
|
+
}
|
|
1154
|
+
com.veeva.clm.wrapResult("updateRecord", callback, ret);
|
|
1155
|
+
} else {
|
|
1156
|
+
ret = {};
|
|
1157
|
+
ret.success = false;
|
|
1158
|
+
ret.code = 2100;
|
|
1159
|
+
ret.message = "Request: " + request + " failed: " + result.message;
|
|
1160
|
+
com.veeva.clm.wrapResult("updateRecord", callback, ret);
|
|
1161
|
+
}
|
|
1162
|
+
};
|
|
1163
|
+
|
|
1164
|
+
if(!com.veeva.clm.testMode)
|
|
1165
|
+
com.veeva.clm.runAPIRequest(request);
|
|
1166
|
+
else
|
|
1167
|
+
com_veeva_clm_updateRecord(com.veeva.clm.testResult.common);
|
|
1168
|
+
},
|
|
1169
|
+
|
|
1170
|
+
// 5a
|
|
1171
|
+
// Navigates to the specified key message (key_message__v)
|
|
1172
|
+
// key message - external id field of the key message to jump to. Usually is media_file_name__v, but does not have to be.
|
|
1173
|
+
// clm presentation - external id of the CLM Presentation if the key message is in a different CLM Presentation.
|
|
1174
|
+
// Usually is presentation_id__v, but does not have to be. Can be made optional by putting in "".
|
|
1175
|
+
gotoSlide: function(keyMessage, presentation) {
|
|
1176
|
+
|
|
1177
|
+
ret = this.checkArgument("keyMessage", keyMessage);
|
|
1178
|
+
if(ret.success == false) {
|
|
1179
|
+
return ret;
|
|
1180
|
+
}
|
|
1181
|
+
|
|
1182
|
+
request = null;
|
|
1183
|
+
if(presentation == undefined || presentation == null || presentation == "") {
|
|
1184
|
+
// goto within current presenation
|
|
1185
|
+
request = "vaultcrm:gotoSlide(" + keyMessage + ")";
|
|
1186
|
+
} else {
|
|
1187
|
+
request = "vaultcrm:gotoSlide(" + keyMessage + "," + presentation + ")";
|
|
1188
|
+
}
|
|
1189
|
+
|
|
1190
|
+
if(!com.veeva.clm.testMode)
|
|
1191
|
+
com.veeva.clm.runAPIRequest(request);
|
|
1192
|
+
|
|
1193
|
+
},
|
|
1194
|
+
|
|
1195
|
+
// 5b
|
|
1196
|
+
// Navigates to the specified key message (key_message__v)
|
|
1197
|
+
// key message - vault_external_id__v field of the key message to jump to
|
|
1198
|
+
// clm presentation - vault_external_id__v of the CLM Presentation if the key message is in a different CLM Presentation.
|
|
1199
|
+
// Can be made optional by putting in "".
|
|
1200
|
+
gotoSlideV2: function(keyMessage, presentation) {
|
|
1201
|
+
|
|
1202
|
+
ret = this.checkArgument("keyMessage", keyMessage);
|
|
1203
|
+
if(ret.success == false) {
|
|
1204
|
+
return ret;
|
|
1205
|
+
}
|
|
1206
|
+
|
|
1207
|
+
request = null;
|
|
1208
|
+
if(presentation == undefined || presentation == null || presentation == "") {
|
|
1209
|
+
// goto within current presentation
|
|
1210
|
+
request = "vaultcrm:gotoSlideV2(" + keyMessage + ")";
|
|
1211
|
+
} else {
|
|
1212
|
+
request = "vaultcrm:gotoSlideV2(" + keyMessage + "," + presentation + ")";
|
|
1213
|
+
}
|
|
1214
|
+
|
|
1215
|
+
if(!com.veeva.clm.testMode)
|
|
1216
|
+
com.veeva.clm.runAPIRequest(request);
|
|
1217
|
+
|
|
1218
|
+
},
|
|
1219
|
+
|
|
1220
|
+
// 6
|
|
1221
|
+
// Navigates to the next slide based on the CLM Presentation Slide display order
|
|
1222
|
+
nextSlide: function() {
|
|
1223
|
+
request = "vaultcrm:nextSlide()";
|
|
1224
|
+
com.veeva.clm.runAPIRequest(request);
|
|
1225
|
+
},
|
|
1226
|
+
|
|
1227
|
+
// 7
|
|
1228
|
+
// Navigates to the previous slide based on the CLM Presentation Slide display order
|
|
1229
|
+
prevSlide: function() {
|
|
1230
|
+
request = "vaultcrm:prevSlide()";
|
|
1231
|
+
com.veeva.clm.runAPIRequest(request);
|
|
1232
|
+
},
|
|
1233
|
+
|
|
1234
|
+
// 8
|
|
1235
|
+
// Returns the value of the field in UTC format. Only works with field of type Date or Datetime.
|
|
1236
|
+
// object - specifies the object api name (object keywords used in getDataForCurrentObject are not valid, except for Account)
|
|
1237
|
+
// record - specifies the record id.
|
|
1238
|
+
// field- field api name to return a value for
|
|
1239
|
+
// callback - call back function which will be used to return the information
|
|
1240
|
+
getUTCdatetime: function(object, record, field, callback) {
|
|
1241
|
+
ret = this.checkCallbackFunction(callback);
|
|
1242
|
+
if(ret.success == false)
|
|
1243
|
+
return ret;
|
|
1244
|
+
|
|
1245
|
+
// check arguments
|
|
1246
|
+
ret = this.checkArgument("object", object);
|
|
1247
|
+
if(ret.success == false) {
|
|
1248
|
+
com.veeva.clm.wrapResult("getUTCdatetime", callback, ret);
|
|
1249
|
+
return;
|
|
1250
|
+
}
|
|
1251
|
+
|
|
1252
|
+
|
|
1253
|
+
ret = this.checkArgument("record", record);
|
|
1254
|
+
if(ret.success == false) {
|
|
1255
|
+
com.veeva.clm.wrapResult("getUTCdatetime", callback, ret);
|
|
1256
|
+
return;
|
|
1257
|
+
}
|
|
1258
|
+
|
|
1259
|
+
ret = this.checkArgument("field", field);
|
|
1260
|
+
if(ret.success == false) {
|
|
1261
|
+
com.veeva.clm.wrapResult("getUTCdatetime", callback, ret);
|
|
1262
|
+
return;
|
|
1263
|
+
}
|
|
1264
|
+
|
|
1265
|
+
window["com_veeva_clm_getUTCdatetime"] = function(result) {
|
|
1266
|
+
// TODO result format
|
|
1267
|
+
com.veeva.clm.wrapResult("getUTCdatetime", callback, result);
|
|
1268
|
+
}
|
|
1269
|
+
|
|
1270
|
+
|
|
1271
|
+
request = "vaultcrm:getDataForObjectV3(" + object + "),objId(" + record + "),fieldName(" + field + "),getUTCdatetime(true),callback(com_veeva_clm_getUTCdatetime)";
|
|
1272
|
+
if(!com.veeva.clm.testMode)
|
|
1273
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1274
|
+
else
|
|
1275
|
+
com_veeva_clm_getUTCdatetime(com.veeva.clm.testResult.common);
|
|
1276
|
+
|
|
1277
|
+
},
|
|
1278
|
+
|
|
1279
|
+
// 9,
|
|
1280
|
+
// Updates the current record related to the call
|
|
1281
|
+
// object - specifies the object api name
|
|
1282
|
+
// values - json object with the fields and values updated on the record (ignores id field if specified)
|
|
1283
|
+
// callback - call back function which will be used to return the information
|
|
1284
|
+
// Uses saveObjectV2 call
|
|
1285
|
+
// Note: This function returns success: true as long as the user has access to the object and record specified.
|
|
1286
|
+
// If the user does not have access to one of the fields specified, success: true is still returned and the fields the user does have access to are updated.
|
|
1287
|
+
// If there are fields which are not accessible, code 0200 is returned and the message specifies the field names.
|
|
1288
|
+
// If there is no current record (user is in Media Preview), the function is temporarily saved and executed when an account__v is selected.
|
|
1289
|
+
// If no account__v is selected, the function is discarded on exit of Media Preview. The callback function will not be executed if there is no current record.
|
|
1290
|
+
updateCurrentRecord: function(object, values, callback) {
|
|
1291
|
+
ret = this.checkCallbackFunction(callback);
|
|
1292
|
+
if(ret.success == false)
|
|
1293
|
+
return ret;
|
|
1294
|
+
|
|
1295
|
+
// check arguments
|
|
1296
|
+
ret = this.checkArgument("object", object);
|
|
1297
|
+
if(ret.success == false) {
|
|
1298
|
+
com.veeva.clm.wrapResult("updateCurrentRecord", callback, ret);
|
|
1299
|
+
return;
|
|
1300
|
+
}
|
|
1301
|
+
|
|
1302
|
+
ret = this.checkArgument("values", values);
|
|
1303
|
+
if(ret.success == false) {
|
|
1304
|
+
com.veeva.clm.wrapResult("updateCurrentRecord", callback, ret);
|
|
1305
|
+
return;
|
|
1306
|
+
}
|
|
1307
|
+
|
|
1308
|
+
// create record
|
|
1309
|
+
request = "vaultcrm:saveObjectV2(" + object + "),updateCurrentRecord(),value(" + JSON.stringify(values) + "),callback(com_veeva_clm_updateCurrentRecord)";
|
|
1310
|
+
|
|
1311
|
+
window["com_veeva_clm_updateCurrentRecord"] = function(result) {
|
|
1312
|
+
result = com.veeva.clm.formatResult(result);
|
|
1313
|
+
if(result.success) {
|
|
1314
|
+
ret = {};
|
|
1315
|
+
ret.success = true;
|
|
1316
|
+
ret[object] = {};
|
|
1317
|
+
ret[object].id = result.objectId;
|
|
1318
|
+
if(result.code != undefined) {
|
|
1319
|
+
ret.code = result.code;
|
|
1320
|
+
ret.message = result.message;
|
|
1321
|
+
}
|
|
1322
|
+
com.veeva.clm.wrapResult("updateCurrentRecord", callback, ret);
|
|
1323
|
+
} else {
|
|
1324
|
+
ret = {};
|
|
1325
|
+
ret.success = false;
|
|
1326
|
+
ret.code = 2100;
|
|
1327
|
+
ret.message = "Request: " + request + " failed: " + result.message;
|
|
1328
|
+
com.veeva.clm.wrapResult("updateCurrentRecord", callback, ret);
|
|
1329
|
+
}
|
|
1330
|
+
};
|
|
1331
|
+
|
|
1332
|
+
if(!com.veeva.clm.testMode)
|
|
1333
|
+
com.veeva.clm.runAPIRequest(request);
|
|
1334
|
+
else
|
|
1335
|
+
com_veeva_clm_updateCurrentRecord(com.veeva.clm.testResult.common);
|
|
1336
|
+
},
|
|
1337
|
+
|
|
1338
|
+
// 10,
|
|
1339
|
+
// Formats a string for createRecordsOnExit() and returns it
|
|
1340
|
+
formatCreateRecords:function(objectArray, valueArray) {
|
|
1341
|
+
//check arguments
|
|
1342
|
+
ret = this.checkArgument("objectArray", objectArray);
|
|
1343
|
+
if(ret.success == false){
|
|
1344
|
+
return ret;
|
|
1345
|
+
}
|
|
1346
|
+
|
|
1347
|
+
ret = this.checkArgument("valueArray", valueArray);
|
|
1348
|
+
if(ret.success == false){
|
|
1349
|
+
return ret;
|
|
1350
|
+
}
|
|
1351
|
+
|
|
1352
|
+
if (!(objectArray instanceof Array)) {
|
|
1353
|
+
objectArray = [objectArray];
|
|
1354
|
+
}
|
|
1355
|
+
if (!(valueArray instanceof Array)) {
|
|
1356
|
+
valueArray = [valueArray];
|
|
1357
|
+
}
|
|
1358
|
+
|
|
1359
|
+
//If the number of objects doesn't match the number of values, return
|
|
1360
|
+
ret = {};
|
|
1361
|
+
if (objectArray.length != valueArray.length) {
|
|
1362
|
+
ret.success = false;
|
|
1363
|
+
ret.code = 2003;
|
|
1364
|
+
ret.message = "Parameter arrays must be of equal length";
|
|
1365
|
+
return ret;
|
|
1366
|
+
}
|
|
1367
|
+
|
|
1368
|
+
//Make the concatenation of all saveObjectV2 requests we need to make
|
|
1369
|
+
var fullString = "";
|
|
1370
|
+
for (var ndx = 0; ndx < objectArray.length; ndx++) {
|
|
1371
|
+
fullString = fullString.concat(com.veeva.clm.generateSaveRecordRequest(objectArray[ndx], valueArray[ndx], "") + ";");
|
|
1372
|
+
}
|
|
1373
|
+
|
|
1374
|
+
return fullString;
|
|
1375
|
+
},
|
|
1376
|
+
|
|
1377
|
+
// 11,
|
|
1378
|
+
// Formats a string for updateRecordsOnExit() and returns it
|
|
1379
|
+
formatUpdateRecords:function(objectNameArray, objectIdArray, valueArray) {
|
|
1380
|
+
//check arguments
|
|
1381
|
+
ret = this.checkArgument("objectNameArray", objectNameArray);
|
|
1382
|
+
if(ret.success == false){
|
|
1383
|
+
return ret;
|
|
1384
|
+
}
|
|
1385
|
+
|
|
1386
|
+
ret = this.checkArgument("objectIdArray", objectIdArray);
|
|
1387
|
+
if(ret.success == false){
|
|
1388
|
+
return ret;
|
|
1389
|
+
}
|
|
1390
|
+
|
|
1391
|
+
ret = this.checkArgument("valueArray", valueArray);
|
|
1392
|
+
if(ret.success == false){
|
|
1393
|
+
return ret;
|
|
1394
|
+
}
|
|
1395
|
+
|
|
1396
|
+
if (!(objectNameArray instanceof Array)) {
|
|
1397
|
+
objectNameArray = [objectNameArray];
|
|
1398
|
+
}
|
|
1399
|
+
if (!(objectIdArray instanceof Array)) {
|
|
1400
|
+
objectIdArray = [objectIdArray];
|
|
1401
|
+
}
|
|
1402
|
+
if (!(valueArray instanceof Array)) {
|
|
1403
|
+
valueArray = [valueArray];
|
|
1404
|
+
}
|
|
1405
|
+
|
|
1406
|
+
//If the number of objects doesn't match the number of values, return
|
|
1407
|
+
ret = {};
|
|
1408
|
+
if (objectNameArray.length != valueArray.length || objectNameArray.length != objectIdArray.length) {
|
|
1409
|
+
ret.success = false;
|
|
1410
|
+
ret.code = 2003;
|
|
1411
|
+
ret.message = "Parameter arrays must be of equal length";
|
|
1412
|
+
return ret;
|
|
1413
|
+
}
|
|
1414
|
+
|
|
1415
|
+
//Make the concatenation of all saveObjectV2 requests we need to make
|
|
1416
|
+
var fullString = "";
|
|
1417
|
+
for (var ndx = 0; ndx < objectNameArray.length; ndx++) {
|
|
1418
|
+
//Set IdNumber in value array
|
|
1419
|
+
valueArray[ndx].IdNumber = objectIdArray[ndx];
|
|
1420
|
+
|
|
1421
|
+
//concat string together
|
|
1422
|
+
fullString = fullString.concat(com.veeva.clm.generateSaveRecordRequest(objectNameArray[ndx], valueArray[ndx], "") + ";");
|
|
1423
|
+
}
|
|
1424
|
+
|
|
1425
|
+
return fullString;
|
|
1426
|
+
},
|
|
1427
|
+
|
|
1428
|
+
// 12,
|
|
1429
|
+
// Creates a string as if it was a request for updateCurrentRecord and returns it
|
|
1430
|
+
formatUpdateCurrentRecords:function(objectArray, valueArray) {
|
|
1431
|
+
//check arguments
|
|
1432
|
+
ret = this.checkArgument("objectArray", objectArray);
|
|
1433
|
+
if(ret.success == false){
|
|
1434
|
+
com.veeva.clm.wrapResult("formatUpdateCurrentRecord", callback, ret);
|
|
1435
|
+
return ret;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
ret = this.checkArgument("valueArray", valueArray);
|
|
1439
|
+
if(ret.success == false){
|
|
1440
|
+
com.veeva.clm.wrapResult("formatUpdateCurrentRecord", callback, ret);
|
|
1441
|
+
return ret;
|
|
1442
|
+
}
|
|
1443
|
+
|
|
1444
|
+
if (!(objectArray instanceof Array)) {
|
|
1445
|
+
objectArray = [objectArray];
|
|
1446
|
+
}
|
|
1447
|
+
if (!(valueArray instanceof Array)) {
|
|
1448
|
+
valueArray = [valueArray];
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
//If the number of objects doesn't match the number of values, return
|
|
1452
|
+
ret = {};
|
|
1453
|
+
if (objectArray.length != valueArray.length) {
|
|
1454
|
+
ret.success = false;
|
|
1455
|
+
ret.code = 2003;
|
|
1456
|
+
ret.message = "Parameter arrays must be of equal length";
|
|
1457
|
+
return ret;
|
|
1458
|
+
}
|
|
1459
|
+
|
|
1460
|
+
//Make the concatenation of all saveObjectV2 requests we need to make
|
|
1461
|
+
var fullString = "";
|
|
1462
|
+
for (var ndx = 0; ndx < objectArray.length; ndx++) {
|
|
1463
|
+
fullString = fullString.concat("vaultcrm:saveObjectV2(" + objectArray[ndx] + "),updateCurrentRecord(),value(" + JSON.stringify(valueArray[ndx]) + "),callback()" + ";");
|
|
1464
|
+
}
|
|
1465
|
+
|
|
1466
|
+
return fullString;
|
|
1467
|
+
},
|
|
1468
|
+
|
|
1469
|
+
//13,
|
|
1470
|
+
// Formats a createRecord or updateRecord request in the proper form
|
|
1471
|
+
generateSaveRecordRequest:function(object, values, callback){
|
|
1472
|
+
return "vaultcrm:saveObjectV2(" + object + "),value(" + JSON.stringify(values) + "),callback(" + callback + ")";
|
|
1473
|
+
},
|
|
1474
|
+
|
|
1475
|
+
//14,
|
|
1476
|
+
// Queries for and returns the specified fields for all records which match the where clause.
|
|
1477
|
+
// Also returns count of records returned.
|
|
1478
|
+
//
|
|
1479
|
+
// object - The API Name of the object that you want to query
|
|
1480
|
+
// fields - Comma delimited string of field API names
|
|
1481
|
+
//
|
|
1482
|
+
// Optional fields:
|
|
1483
|
+
// where - string for the where clause (See documentation for supported clauses).
|
|
1484
|
+
// sort - Array of strings which represents the sort, example: ["name__v, DESC", "status__v, ASC"]
|
|
1485
|
+
// limit - the maximum number of records to return
|
|
1486
|
+
queryRecord:function(object, fields, where, sort, limit, callback){
|
|
1487
|
+
ret = this.checkCallbackFunction(callback);
|
|
1488
|
+
if(ret.success == false)
|
|
1489
|
+
return ret;
|
|
1490
|
+
|
|
1491
|
+
// check arguments
|
|
1492
|
+
ret = this.checkArgument("object", object);
|
|
1493
|
+
if(ret.success == false) {
|
|
1494
|
+
com.veeva.clm.wrapResult("queryRecord", callback, ret);
|
|
1495
|
+
return;
|
|
1496
|
+
}
|
|
1497
|
+
|
|
1498
|
+
ret = this.checkArgument("fields", fields);
|
|
1499
|
+
if(ret.success == false) {
|
|
1500
|
+
com.veeva.clm.wrapResult("queryRecord", callback, ret);
|
|
1501
|
+
return;
|
|
1502
|
+
}
|
|
1503
|
+
|
|
1504
|
+
//Don't check the Where, limit, or sort clauses because they can be null and thats acceptable.
|
|
1505
|
+
|
|
1506
|
+
window["com_veeva_clm_queryRecordReturn"] = function(result) {
|
|
1507
|
+
result = com.veeva.clm.formatResult(result);
|
|
1508
|
+
com.veeva.clm.wrapResult("queryRecord", callback, result);
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
|
|
1512
|
+
request = "vaultcrm:queryObject(" + object + "),fields(" + fields + "),";
|
|
1513
|
+
if (where != null && where != undefined) {
|
|
1514
|
+
request = request + "where(" + where + "),";
|
|
1515
|
+
}
|
|
1516
|
+
if (sort != null && sort != undefined) {
|
|
1517
|
+
request = request + "sort(" + JSON.stringify(sort) + "),";
|
|
1518
|
+
}
|
|
1519
|
+
if (limit != null && limit != undefined) {
|
|
1520
|
+
request = request + "limit(" + limit + "),";
|
|
1521
|
+
}
|
|
1522
|
+
request = request + "com_veeva_clm_queryRecordReturn(result)";
|
|
1523
|
+
|
|
1524
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1525
|
+
},
|
|
1526
|
+
|
|
1527
|
+
//15,
|
|
1528
|
+
// Returns the translated label for each of the specified fields
|
|
1529
|
+
//
|
|
1530
|
+
// object - API Name of the object
|
|
1531
|
+
// fields - Array of Field API Names
|
|
1532
|
+
getFieldLabel:function(object, fields, callback){
|
|
1533
|
+
ret = this.checkCallbackFunction(callback);
|
|
1534
|
+
if(ret.success == false)
|
|
1535
|
+
return ret;
|
|
1536
|
+
|
|
1537
|
+
// check arguments
|
|
1538
|
+
ret = this.checkArgument("object", object);
|
|
1539
|
+
if(ret.success == false) {
|
|
1540
|
+
com.veeva.clm.wrapResult("getFieldLabel", callback, ret);
|
|
1541
|
+
return;
|
|
1542
|
+
}
|
|
1543
|
+
|
|
1544
|
+
ret = this.checkArgument("fields", fields);
|
|
1545
|
+
if(ret.success == false) {
|
|
1546
|
+
com.veeva.clm.wrapResult("getFieldLabel", callback, ret);
|
|
1547
|
+
return;
|
|
1548
|
+
}
|
|
1549
|
+
|
|
1550
|
+
window["com_veeva_clm_getFieldLabelReturn"] = function(result) {
|
|
1551
|
+
result = com.veeva.clm.formatResult(result);
|
|
1552
|
+
com.veeva.clm.wrapResult("getFieldLabel", callback, result);
|
|
1553
|
+
return;
|
|
1554
|
+
}
|
|
1555
|
+
|
|
1556
|
+
request = "vaultcrm:getFieldLabel(" + object + "),fields(" + JSON.stringify(fields) + "), com_veeva_clm_getFieldLabelReturn(result)";
|
|
1557
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1558
|
+
},
|
|
1559
|
+
|
|
1560
|
+
//16,
|
|
1561
|
+
// Returns each object type api name and object type translated label
|
|
1562
|
+
//
|
|
1563
|
+
// object - API Name of the object to get all record types for
|
|
1564
|
+
getObjectTypeLabels:function(object, callback){
|
|
1565
|
+
ret = this.checkCallbackFunction(callback);
|
|
1566
|
+
if(ret.success == false)
|
|
1567
|
+
return ret;
|
|
1568
|
+
|
|
1569
|
+
// check arguments
|
|
1570
|
+
ret = this.checkArgument("object", object);
|
|
1571
|
+
if(ret.success == false) {
|
|
1572
|
+
com.veeva.clm.wrapResult("getObjectTypeLabels", callback, ret);
|
|
1573
|
+
return;
|
|
1574
|
+
}
|
|
1575
|
+
|
|
1576
|
+
window["com_veeva_clm_getObjectTypeLabelsReturn"] = function(result) {
|
|
1577
|
+
result = com.veeva.clm.formatResult(result);
|
|
1578
|
+
com.veeva.clm.wrapResult("getObjectTypeLabels", callback, result);
|
|
1579
|
+
return;
|
|
1580
|
+
}
|
|
1581
|
+
|
|
1582
|
+
request = "vaultcrm:getObjectTypeLabels(" + object + "),com_veeva_clm_getObjectTypeLabelsReturn(result)";
|
|
1583
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1584
|
+
},
|
|
1585
|
+
|
|
1586
|
+
// Wrapper for backward compatibility with the Salesforce-based CLM content
|
|
1587
|
+
getRecordTypeLabels:function(object, callback){
|
|
1588
|
+
this.getObjectTypeLabels(object, callback);
|
|
1589
|
+
},
|
|
1590
|
+
|
|
1591
|
+
//17,
|
|
1592
|
+
// Returns the translated label for each of the picklist values of the specified field
|
|
1593
|
+
//
|
|
1594
|
+
// object - API Name of the object
|
|
1595
|
+
// field - API Name of the picklist field
|
|
1596
|
+
getPicklistValueLabels:function(object, field, callback){
|
|
1597
|
+
ret = this.checkCallbackFunction(callback);
|
|
1598
|
+
if(ret.success == false)
|
|
1599
|
+
return ret;
|
|
1600
|
+
|
|
1601
|
+
// check arguments
|
|
1602
|
+
ret = this.checkArgument("object", object);
|
|
1603
|
+
if(ret.success == false) {
|
|
1604
|
+
com.veeva.clm.wrapResult("getPicklistValueLabels", callback, ret);
|
|
1605
|
+
return;
|
|
1606
|
+
}
|
|
1607
|
+
|
|
1608
|
+
ret = this.checkArgument("field", field);
|
|
1609
|
+
if(ret.success == false) {
|
|
1610
|
+
com.veeva.clm.wrapResult("getPicklistValueLabels", callback, ret);
|
|
1611
|
+
return;
|
|
1612
|
+
}
|
|
1613
|
+
|
|
1614
|
+
window["com_veeva_clm_getPicklistValueLabelsReturn"] = function(result) {
|
|
1615
|
+
result = com.veeva.clm.formatResult(result);
|
|
1616
|
+
com.veeva.clm.wrapResult("getPicklistValueLabels", callback, result);
|
|
1617
|
+
return;
|
|
1618
|
+
}
|
|
1619
|
+
|
|
1620
|
+
request = "vaultcrm:getPicklistValueLabels(" + object + "),field(" + field + "), com_veeva_clm_getPicklistValueLabelsReturn(result)";
|
|
1621
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1622
|
+
},
|
|
1623
|
+
|
|
1624
|
+
//18,
|
|
1625
|
+
// Returns object translated labels array for each object API name
|
|
1626
|
+
// objects - array of object API Names to get translated labels for
|
|
1627
|
+
getObjectLabels:function(objects, callback){
|
|
1628
|
+
var ret = this.checkCallbackFunction(callback);
|
|
1629
|
+
if(ret.success == false)
|
|
1630
|
+
return ret;
|
|
1631
|
+
|
|
1632
|
+
// check arguments
|
|
1633
|
+
ret = this.checkArgument("objects", objects);
|
|
1634
|
+
if(ret.success == false) {
|
|
1635
|
+
com.veeva.clm.wrapResult("getObjectLabels", callback, ret);
|
|
1636
|
+
return;
|
|
1637
|
+
}
|
|
1638
|
+
|
|
1639
|
+
window["com_veeva_clm_getObjectLabelsReturn"] = function(result) {
|
|
1640
|
+
result = com.veeva.clm.formatResult(result);
|
|
1641
|
+
com.veeva.clm.wrapResult("getObjectLabels", callback, result);
|
|
1642
|
+
return;
|
|
1643
|
+
}
|
|
1644
|
+
|
|
1645
|
+
request = "vaultcrm:getObjectLabels(" + JSON.stringify(objects) + "),com_veeva_clm_getObjectLabelsReturn(result)";
|
|
1646
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1647
|
+
},
|
|
1648
|
+
|
|
1649
|
+
//19,
|
|
1650
|
+
// Returns HTTP Request result
|
|
1651
|
+
//
|
|
1652
|
+
// object - request object with all HTTP parameters
|
|
1653
|
+
request:function(object, callback){
|
|
1654
|
+
ret = this.checkCallbackFunction(callback);
|
|
1655
|
+
if(!ret.success) {
|
|
1656
|
+
return ret;
|
|
1657
|
+
}
|
|
1658
|
+
|
|
1659
|
+
//check request object validity
|
|
1660
|
+
var errorMessage = this.validateRequestObjectWithErrorMessage(object);
|
|
1661
|
+
if (errorMessage !== "Valid") {
|
|
1662
|
+
var error = {
|
|
1663
|
+
success: false,
|
|
1664
|
+
code: 5,
|
|
1665
|
+
message: errorMessage
|
|
1666
|
+
};
|
|
1667
|
+
com.veeva.clm.wrapResult("request", callback, error);
|
|
1668
|
+
return;
|
|
1669
|
+
}
|
|
1670
|
+
|
|
1671
|
+
this.addRequestObjectDefaultsAndFormat(object);
|
|
1672
|
+
|
|
1673
|
+
window["com_veeva_clm_requestReturn"] = function(result) {
|
|
1674
|
+
result = com.veeva.clm.formatResult(result);
|
|
1675
|
+
com.veeva.clm.wrapResult("request", callback, result);
|
|
1676
|
+
return;
|
|
1677
|
+
};
|
|
1678
|
+
|
|
1679
|
+
var request = "vaultcrm:request(" + JSON.stringify(object) + "),com_veeva_clm_requestReturn(result)";
|
|
1680
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1681
|
+
},
|
|
1682
|
+
|
|
1683
|
+
//20,
|
|
1684
|
+
// Returns the version of the current offline application
|
|
1685
|
+
getAppVersion: function(callback) {
|
|
1686
|
+
ret = this.checkCallbackFunction(callback);
|
|
1687
|
+
if(ret.success == false)
|
|
1688
|
+
return ret;
|
|
1689
|
+
|
|
1690
|
+
window.com_veeva_clm_appVersion = function(result) {
|
|
1691
|
+
clearTimeout(timer);
|
|
1692
|
+
com.veeva.clm.wrapResult("getAppVersion", callback, result);
|
|
1693
|
+
}
|
|
1694
|
+
|
|
1695
|
+
var timer = setTimeout(function() {
|
|
1696
|
+
result = { success: false };
|
|
1697
|
+
com.veeva.clm.wrapResult("getAppVersion", callback, result);
|
|
1698
|
+
}, 1500);
|
|
1699
|
+
|
|
1700
|
+
query = "vaultcrm:getAppVersion(),com_veeva_clm_appVersion(result)";
|
|
1701
|
+
if(!com.veeva.clm.testMode) {
|
|
1702
|
+
com.veeva.clm.runAPIRequest(query);
|
|
1703
|
+
} else {
|
|
1704
|
+
com_veeva_clm_appVersion(com.veeva.clm.testResult.common);
|
|
1705
|
+
}
|
|
1706
|
+
},
|
|
1707
|
+
|
|
1708
|
+
/////////////////////// CLM Specific ///////////////////////
|
|
1709
|
+
//1,
|
|
1710
|
+
// Shows slide selector with specified presentation:key messages; callback gets notified if there aren't any valid key messages
|
|
1711
|
+
// The selector shows presentations in the same order as requested, but slide are in the order as defined in the presentation,
|
|
1712
|
+
// not the order specified in the request.
|
|
1713
|
+
launchSelector: function(presentationSlides, callback) {
|
|
1714
|
+
// check parameter
|
|
1715
|
+
var ret = this.checkCallbackFunction(callback);
|
|
1716
|
+
if(ret.success == false)
|
|
1717
|
+
return ret;
|
|
1718
|
+
|
|
1719
|
+
// check arguments
|
|
1720
|
+
ret = this.checkArgument("presentationSlides", presentationSlides);
|
|
1721
|
+
if(ret.success == false) {
|
|
1722
|
+
com.veeva.clm.wrapResult("presentationSlides", callback, ret);
|
|
1723
|
+
return;
|
|
1724
|
+
}
|
|
1725
|
+
|
|
1726
|
+
if(presentationSlides.constructor === Array){
|
|
1727
|
+
// check each element for empty presentation id
|
|
1728
|
+
for(var i=0; i < presentationSlides.length; i++){
|
|
1729
|
+
var presentationMessages = presentationSlides[i]
|
|
1730
|
+
if(presentationMessages != null && typeof(presentationMessages) === 'object'){
|
|
1731
|
+
for(var prop in presentationMessages){
|
|
1732
|
+
if(presentationMessages.hasOwnProperty(prop) && prop == ""){
|
|
1733
|
+
// empty presentastion id
|
|
1734
|
+
ret = {};
|
|
1735
|
+
ret.success = false;
|
|
1736
|
+
ret.code = 2002;
|
|
1737
|
+
ret.message = "presentation id is empty";
|
|
1738
|
+
com.veeva.clm.wrapResult("presentationSlides", callback, ret);
|
|
1739
|
+
return;
|
|
1740
|
+
}
|
|
1741
|
+
}
|
|
1742
|
+
}
|
|
1743
|
+
|
|
1744
|
+
}
|
|
1745
|
+
}
|
|
1746
|
+
|
|
1747
|
+
var request = null;
|
|
1748
|
+
window["com_veeva_clm_launchApprovedEmail"] = function(result) {
|
|
1749
|
+
result = com.veeva.clm.formatResult(result);
|
|
1750
|
+
var ret = {};
|
|
1751
|
+
if(result.success) {
|
|
1752
|
+
ret.success = true;
|
|
1753
|
+
if(result.code != undefined) {
|
|
1754
|
+
ret.code = result.code;
|
|
1755
|
+
ret.message = result.message;
|
|
1756
|
+
}
|
|
1757
|
+
com.veeva.clm.wrapResult("launchSelector", callback, ret);
|
|
1758
|
+
} else {
|
|
1759
|
+
ret.success = false;
|
|
1760
|
+
ret.code = result.code;
|
|
1761
|
+
ret.message = "Request: " + request + " failed: " + result.message;
|
|
1762
|
+
com.veeva.clm.wrapResult("launchSelector", callback, ret);
|
|
1763
|
+
}
|
|
1764
|
+
};
|
|
1765
|
+
|
|
1766
|
+
request = "vaultcrm:launchSelector(" + JSON.stringify(presentationSlides) + "),callback(com_veeva_clm_launchSelector)";
|
|
1767
|
+
|
|
1768
|
+
if(!com.veeva.clm.testMode)
|
|
1769
|
+
com.veeva.clm.runAPIRequest(request);
|
|
1770
|
+
else
|
|
1771
|
+
com_veeva_clm_launchSelector(com.veeva.clm.testResult.launchSelectorResult);
|
|
1772
|
+
|
|
1773
|
+
},
|
|
1774
|
+
|
|
1775
|
+
/////////////////////// Engage ///////////////////////
|
|
1776
|
+
|
|
1777
|
+
// 1,
|
|
1778
|
+
// Creates a new record for Multichannel activity line. The Engage code will automatically fill in the Multichannel Activity,
|
|
1779
|
+
// Asset Version, Asset VExternal id, Call (if there is one), DateTime, Debug?, Multichannel Content, Multichannel Content Asset,
|
|
1780
|
+
// Sent Email (if there is one), View Order (if Event Type = Slide View). Custom = "True" will always be set and the Name is autonumbered.
|
|
1781
|
+
// If not specified with custom values, Detail Group, Detail Group VExternal Id, Key Message, Key Message VExternal id, Product,
|
|
1782
|
+
// Product VExternal id are also automatically filled in.
|
|
1783
|
+
// values - json object with the fields and values updated on the record
|
|
1784
|
+
// callback - call back function which will be used to return the information
|
|
1785
|
+
createMultichannelActivityLine: function(values, callback) {
|
|
1786
|
+
ret = this.checkCallbackFunction(callback);
|
|
1787
|
+
if(ret.success == false)
|
|
1788
|
+
return ret;
|
|
1789
|
+
|
|
1790
|
+
ret = this.checkArgument("values", values);
|
|
1791
|
+
if(ret.success == false) {
|
|
1792
|
+
com.veeva.clm.wrapResult("createMultichannelActivityLine", callback, ret);
|
|
1793
|
+
return;
|
|
1794
|
+
}
|
|
1795
|
+
|
|
1796
|
+
window["com_veeva_clm_createActivityLine"] = function(result) {
|
|
1797
|
+
com.veeva.clm.wrapResult("createMultichannelActivityLine", callback, result);
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1800
|
+
request = "vaultcrm:createActivityLine(),value(" + JSON.stringify(values) + "),com_veeva_clm_createActivityLine(result)";
|
|
1801
|
+
com.veeva.clm.runAPIRequest(request, callback);
|
|
1802
|
+
},
|
|
1803
|
+
|
|
1804
|
+
/////////////////////// Supporting Functions ///////////////////////
|
|
1805
|
+
|
|
1806
|
+
// join string array to a in expression
|
|
1807
|
+
joinStringArrayForContains: function(result) {
|
|
1808
|
+
var ret = "";
|
|
1809
|
+
if(result.length > 0) {
|
|
1810
|
+
for(i = 0; i < result.length; i++) {
|
|
1811
|
+
if(i == 0)
|
|
1812
|
+
ret += "('" + result[i] + "'";
|
|
1813
|
+
else {
|
|
1814
|
+
ret += ",'" + result[i] + "'";
|
|
1815
|
+
}
|
|
1816
|
+
|
|
1817
|
+
}
|
|
1818
|
+
ret += ")";
|
|
1819
|
+
}
|
|
1820
|
+
|
|
1821
|
+
return ret;
|
|
1822
|
+
},
|
|
1823
|
+
|
|
1824
|
+
joinFieldArray: function(fields) {
|
|
1825
|
+
var ret = "";
|
|
1826
|
+
if(fields.length > 0) {
|
|
1827
|
+
for(i = 0; i < fields.length; i++) {
|
|
1828
|
+
if(i == 0)
|
|
1829
|
+
ret += fields[i];
|
|
1830
|
+
else {
|
|
1831
|
+
ret += "," + fields[i];
|
|
1832
|
+
}
|
|
1833
|
+
|
|
1834
|
+
}
|
|
1835
|
+
}
|
|
1836
|
+
|
|
1837
|
+
return ret;
|
|
1838
|
+
},
|
|
1839
|
+
|
|
1840
|
+
isFunction: function(toCheck) {
|
|
1841
|
+
var getType = {};
|
|
1842
|
+
return toCheck && getType.toString.call(toCheck) === '[object Function]';
|
|
1843
|
+
},
|
|
1844
|
+
|
|
1845
|
+
checkCallbackFunction: function(toCheck) {
|
|
1846
|
+
// check arguments
|
|
1847
|
+
ret = {};
|
|
1848
|
+
if(toCheck == undefined) {
|
|
1849
|
+
ret.success = false;
|
|
1850
|
+
ret.code = 2000
|
|
1851
|
+
ret.message = "callback is missing";
|
|
1852
|
+
return ret;
|
|
1853
|
+
}
|
|
1854
|
+
|
|
1855
|
+
if(this.isFunction(toCheck) == false) {
|
|
1856
|
+
ret.success = false;
|
|
1857
|
+
ret.code = 2001;
|
|
1858
|
+
ret.message = "callback is not a JavaScript function";
|
|
1859
|
+
} else {
|
|
1860
|
+
ret.success = true;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
return ret;
|
|
1864
|
+
},
|
|
1865
|
+
|
|
1866
|
+
checkArgument: function(name, value) {
|
|
1867
|
+
ret = {};
|
|
1868
|
+
ret.success = true;
|
|
1869
|
+
if(value == undefined || value == null || value == "") {
|
|
1870
|
+
ret.success = false;
|
|
1871
|
+
ret.code = 2002;
|
|
1872
|
+
ret.message = name + " is empty";
|
|
1873
|
+
}
|
|
1874
|
+
|
|
1875
|
+
|
|
1876
|
+
return ret;
|
|
1877
|
+
},
|
|
1878
|
+
|
|
1879
|
+
validateRequestObjectWithErrorMessage: function(request) {
|
|
1880
|
+
var errorString = "";
|
|
1881
|
+
|
|
1882
|
+
//validate that an object is passed in
|
|
1883
|
+
if (typeof request !== "object") {
|
|
1884
|
+
errorString = "Invalid request. Must be an object.";
|
|
1885
|
+
}
|
|
1886
|
+
//validate url
|
|
1887
|
+
//url must be a string
|
|
1888
|
+
//value is required
|
|
1889
|
+
else if (typeof request.url !== "string" || request.url.length <= 0) {
|
|
1890
|
+
errorString = "Invalid URL value. Must be a non-empty String";
|
|
1891
|
+
}
|
|
1892
|
+
//validate method
|
|
1893
|
+
//method must be one of the valid HTTP verbs
|
|
1894
|
+
//optional
|
|
1895
|
+
else if (request.method && !this.validateMethod(request.method)) {
|
|
1896
|
+
errorString = "Invalid method value. Must be a valid HTTP method.";
|
|
1897
|
+
}
|
|
1898
|
+
//validate headers
|
|
1899
|
+
//must be an object whose values are all strings
|
|
1900
|
+
//optional
|
|
1901
|
+
else if (request.headers && !this.validateHeaders(request.headers)) {
|
|
1902
|
+
errorString = "Invalid headers value. Must be an object with values of type String";
|
|
1903
|
+
}
|
|
1904
|
+
//validate timeout
|
|
1905
|
+
//must be a number
|
|
1906
|
+
//optional
|
|
1907
|
+
else if (request.timeout && (typeof request.timeout !== "number" || request.timeout <= 0)) {
|
|
1908
|
+
errorString = "Invalid timeout value. Must be a positive number";
|
|
1909
|
+
}
|
|
1910
|
+
//validate expect
|
|
1911
|
+
//must be a "text" or "blob"
|
|
1912
|
+
//optional
|
|
1913
|
+
else if (request.expect && !this.validateExpect(request.expect)) {
|
|
1914
|
+
errorString = "Invalid expect value. Must be a String of value 'text' or 'blob'";
|
|
1915
|
+
}
|
|
1916
|
+
else {
|
|
1917
|
+
errorString = "Valid";
|
|
1918
|
+
}
|
|
1919
|
+
|
|
1920
|
+
return errorString;
|
|
1921
|
+
},
|
|
1922
|
+
|
|
1923
|
+
methods: ['POST', 'GET', 'HEAD', 'PUT', 'DELETE', 'CONNECT', 'OPTIONS', 'TRACE', 'PATCH'],
|
|
1924
|
+
|
|
1925
|
+
validateMethod: function(method) {
|
|
1926
|
+
return typeof method === "string" && !!~this.methods.indexOf(method.toUpperCase());
|
|
1927
|
+
},
|
|
1928
|
+
|
|
1929
|
+
validateHeaders: function(headers) {
|
|
1930
|
+
if (typeof headers === "object") {
|
|
1931
|
+
var keys = Object.keys(headers);
|
|
1932
|
+
for (var i = 0; i < keys.length; i++) {
|
|
1933
|
+
var key = keys[i];
|
|
1934
|
+
var headerValue = headers[key];
|
|
1935
|
+
if (typeof headerValue !== "string") {
|
|
1936
|
+
return false;
|
|
1937
|
+
}
|
|
1938
|
+
}
|
|
1939
|
+
} else {
|
|
1940
|
+
return false;
|
|
1941
|
+
}
|
|
1942
|
+
return true;
|
|
1943
|
+
},
|
|
1944
|
+
|
|
1945
|
+
validateExpect: function(expect) {
|
|
1946
|
+
return typeof expect === "string" && (expect.toLowerCase() === "text" || expect.toLowerCase() === "blob");
|
|
1947
|
+
},
|
|
1948
|
+
|
|
1949
|
+
addRequestObjectDefaultsAndFormat: function(request) {
|
|
1950
|
+
if (!request.method) {
|
|
1951
|
+
request.method = "GET";
|
|
1952
|
+
} else {
|
|
1953
|
+
request.method = request.method.toUpperCase();
|
|
1954
|
+
}
|
|
1955
|
+
if (!request.headers) {
|
|
1956
|
+
request.headers = {};
|
|
1957
|
+
}
|
|
1958
|
+
if (!request.timeout) {
|
|
1959
|
+
request.timeout = 30;
|
|
1960
|
+
}
|
|
1961
|
+
if (!request.body) {
|
|
1962
|
+
request.body = "";
|
|
1963
|
+
}
|
|
1964
|
+
if (!request.expect) {
|
|
1965
|
+
request.expect = "text";
|
|
1966
|
+
} else {
|
|
1967
|
+
request.expect = request.expect.toLowerCase();
|
|
1968
|
+
}
|
|
1969
|
+
},
|
|
1970
|
+
|
|
1971
|
+
getCurrentDate: function() {
|
|
1972
|
+
var currentDate = new Date();
|
|
1973
|
+
dateString = currentDate.getFullYear().toString();
|
|
1974
|
+
month = currentDate.getMonth() + 1;
|
|
1975
|
+
if(month < 10) {
|
|
1976
|
+
dateString += "-0" + month;
|
|
1977
|
+
}
|
|
1978
|
+
else {
|
|
1979
|
+
dateString += "-" + month;
|
|
1980
|
+
}
|
|
1981
|
+
date = currentDate.getDate();
|
|
1982
|
+
if(date < 10) {
|
|
1983
|
+
dateString += "-0" + date;
|
|
1984
|
+
} else {
|
|
1985
|
+
dateString += "-" + date;
|
|
1986
|
+
}
|
|
1987
|
+
|
|
1988
|
+
return dateString;
|
|
1989
|
+
},
|
|
1990
|
+
|
|
1991
|
+
formatResult: function(result) {
|
|
1992
|
+
if(com.veeva.clm.isWin8()) {
|
|
1993
|
+
if(typeof result == "string") {
|
|
1994
|
+
result = eval("(" + result + ")");
|
|
1995
|
+
}
|
|
1996
|
+
}
|
|
1997
|
+
return result;
|
|
1998
|
+
},
|
|
1999
|
+
|
|
2000
|
+
wrapResult: function(apiName, userCallback, result) {
|
|
2001
|
+
result = com.veeva.clm.formatResult(result);
|
|
2002
|
+
if(result.success)
|
|
2003
|
+
userCallback(result);
|
|
2004
|
+
else {
|
|
2005
|
+
result.message = apiName + ": " + result.message;
|
|
2006
|
+
userCallback(result);
|
|
2007
|
+
}
|
|
2008
|
+
},
|
|
2009
|
+
|
|
2010
|
+
runAPIRequest: function(request, callback) {
|
|
2011
|
+
if(com.veeva.clm.isEngage()) {
|
|
2012
|
+
com.veeva.clm.engageAPIRequest(request, callback);
|
|
2013
|
+
} else if(com.veeva.clm.isWin8()) {
|
|
2014
|
+
window.external.notify(request);
|
|
2015
|
+
} else if(com.veeva.clm.isVeevaMessagingEnabled()) {
|
|
2016
|
+
window.webkit.messageHandlers.veeva.postMessage({"message": request});
|
|
2017
|
+
} else {
|
|
2018
|
+
// existing code in this block could be deleted, but to play safe, we keep
|
|
2019
|
+
// as is just in case some legacy applications still need them.
|
|
2020
|
+
// we will eventually remove this code block.
|
|
2021
|
+
request = request.replace(/^vaultcrm:/, '');
|
|
2022
|
+
request = encodeURIComponent(request);
|
|
2023
|
+
request = "vaultcrm:" + request;
|
|
2024
|
+
document.location = request;
|
|
2025
|
+
}
|
|
2026
|
+
},
|
|
2027
|
+
|
|
2028
|
+
isVeevaMessagingEnabled: function() {
|
|
2029
|
+
return Boolean(window.webkit.messageHandlers.veeva);
|
|
2030
|
+
},
|
|
2031
|
+
|
|
2032
|
+
isWin8: function() {
|
|
2033
|
+
if(navigator.platform.toLowerCase().indexOf("win") >= 0)
|
|
2034
|
+
return true;
|
|
2035
|
+
else
|
|
2036
|
+
return false;
|
|
2037
|
+
},
|
|
2038
|
+
|
|
2039
|
+
|
|
2040
|
+
isEngage: function() {
|
|
2041
|
+
if(window.self !== window.top) {
|
|
2042
|
+
return true;
|
|
2043
|
+
}
|
|
2044
|
+
return false;
|
|
2045
|
+
},
|
|
2046
|
+
|
|
2047
|
+
engageAPIRequest: function(request, callback) {
|
|
2048
|
+
if(com.veeva.clm.engageHasListener === false) {
|
|
2049
|
+
com.veeva.clm.engageHasListener = true;
|
|
2050
|
+
com.veeva.clm.engageCallbackId = 0;
|
|
2051
|
+
function receiveMessage(event) {
|
|
2052
|
+
var data = JSON.parse(event.data);
|
|
2053
|
+
var callbackId = data.callback;
|
|
2054
|
+
if(callbackId !== undefined && callbackId !== null) {
|
|
2055
|
+
var callbackFunc = com.veeva.clm.engageCallbackList[callbackId];
|
|
2056
|
+
if(callbackFunc !== undefined && callbackFunc !== null) {
|
|
2057
|
+
callbackFunc.call(null, data);
|
|
2058
|
+
// don't want to splice because that would change the length
|
|
2059
|
+
// of the array and could affect the index based access
|
|
2060
|
+
delete com.veeva.clm.engageCallbackList[callbackId];
|
|
2061
|
+
}
|
|
2062
|
+
}
|
|
2063
|
+
}
|
|
2064
|
+
|
|
2065
|
+
if(!window.addEventListener) {
|
|
2066
|
+
window.attachEvent("onmessage", receiveMessage);
|
|
2067
|
+
} else {
|
|
2068
|
+
window.addEventListener("message", receiveMessage, false);
|
|
2069
|
+
}
|
|
2070
|
+
}
|
|
2071
|
+
setTimeout(function() {
|
|
2072
|
+
com.veeva.clm.engageCallbackId += 1;
|
|
2073
|
+
var callbackId = com.veeva.clm.engageCallbackId;
|
|
2074
|
+
com.veeva.clm.engageCallbackList[callbackId] = callback;
|
|
2075
|
+
var tokens = request.split("),");
|
|
2076
|
+
if(tokens.length > 1) {
|
|
2077
|
+
// replace the last token (the original callback) with a callback id
|
|
2078
|
+
tokens[tokens.length - 1 ] = callbackId;
|
|
2079
|
+
request = tokens.join("),");
|
|
2080
|
+
}
|
|
2081
|
+
window.parent.postMessage(request, "*");
|
|
2082
|
+
|
|
2083
|
+
}, 1);
|
|
2084
|
+
},
|
|
2085
|
+
|
|
2086
|
+
listPriceObjectTypeId: null,
|
|
2087
|
+
accountId: null,
|
|
2088
|
+
addressId: null,
|
|
2089
|
+
callId: null,
|
|
2090
|
+
tsfId: null,
|
|
2091
|
+
userId: null,
|
|
2092
|
+
presentationId: null,
|
|
2093
|
+
keyMessageId: null,
|
|
2094
|
+
engageHasListener: false,
|
|
2095
|
+
engageCallbackId: null,
|
|
2096
|
+
engageCallbackList: [],
|
|
2097
|
+
testMode: false,
|
|
2098
|
+
testResult: null
|
|
2099
|
+
|
|
2100
|
+
};
|
|
2101
|
+
|
|
2102
|
+
com.veeva.clm.initialize = function initializeEngage() {
|
|
2103
|
+
var internalMessage = false;
|
|
2104
|
+
var frameScale = 1;
|
|
2105
|
+
|
|
2106
|
+
if(!window.addEventListener) {
|
|
2107
|
+
window.attachEvent("onmessage", engageMessage);
|
|
2108
|
+
} else {
|
|
2109
|
+
window.addEventListener("message", engageMessage, false);
|
|
2110
|
+
}
|
|
2111
|
+
|
|
2112
|
+
document.onmousemove = function(event) {
|
|
2113
|
+
if(internalMessage === true) {
|
|
2114
|
+
return;
|
|
2115
|
+
}
|
|
2116
|
+
|
|
2117
|
+
var e = event || window.event;
|
|
2118
|
+
sendMouseEvent(e, "mousemove");
|
|
2119
|
+
};
|
|
2120
|
+
|
|
2121
|
+
document.onclick = function(event) {
|
|
2122
|
+
if(internalMessage === true) {
|
|
2123
|
+
return;
|
|
2124
|
+
}
|
|
2125
|
+
|
|
2126
|
+
var e = event || window.event;
|
|
2127
|
+
sendMouseEvent(e, "click");
|
|
2128
|
+
};
|
|
2129
|
+
|
|
2130
|
+
document.onchange = function(event) {
|
|
2131
|
+
if(internalMessage === true) {
|
|
2132
|
+
return;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
var e = event || window.event;
|
|
2136
|
+
var target = e.target || e.srcElement;
|
|
2137
|
+
|
|
2138
|
+
if(target) {
|
|
2139
|
+
var eLocation = {};
|
|
2140
|
+
var offsetSum = getOffset(target);
|
|
2141
|
+
eLocation.x = offsetSum.left + target.offsetWidth/2;
|
|
2142
|
+
eLocation.y = offsetSum.top + target.offsetHeight/2;
|
|
2143
|
+
sendChangeEvent("change", target, eLocation);
|
|
2144
|
+
}
|
|
2145
|
+
};
|
|
2146
|
+
|
|
2147
|
+
document.onkeypress = function(event) {
|
|
2148
|
+
if(internalMessage === true) {
|
|
2149
|
+
return;
|
|
2150
|
+
}
|
|
2151
|
+
|
|
2152
|
+
var e = event || window.event;
|
|
2153
|
+
var target = e.target || e.srcElement;
|
|
2154
|
+
|
|
2155
|
+
if(target) {
|
|
2156
|
+
var keyCode = (typeof e.which === "number") ? e.which : e.keyCode;
|
|
2157
|
+
//Only transmit return keypress
|
|
2158
|
+
if(keyCode === 13) {
|
|
2159
|
+
var eLocation = {};
|
|
2160
|
+
var offsetSum = getOffset(target);
|
|
2161
|
+
eLocation.x = offsetSum.left + target.offsetWidth/2;
|
|
2162
|
+
eLocation.y = offsetSum.top + target.offsetHeight/2;
|
|
2163
|
+
sendKeyboardEvent("keypress", keyCode, eLocation);
|
|
2164
|
+
}
|
|
2165
|
+
}
|
|
2166
|
+
};
|
|
2167
|
+
|
|
2168
|
+
document.onscroll = function(event) {
|
|
2169
|
+
if(internalMessage === true) {
|
|
2170
|
+
return;
|
|
2171
|
+
}
|
|
2172
|
+
|
|
2173
|
+
var e = event || window.event;
|
|
2174
|
+
var target = e.target || e.srcElement;
|
|
2175
|
+
|
|
2176
|
+
if(target) {
|
|
2177
|
+
var scrollPosition = {};
|
|
2178
|
+
if(target.scrollingElement) {
|
|
2179
|
+
scrollPosition.left = target.scrollingElement.scrollLeft;
|
|
2180
|
+
scrollPosition.top = target.scrollingElement.scrollTop;
|
|
2181
|
+
} else if(target.documentElement) {
|
|
2182
|
+
scrollPosition.left = target.documentElement.scrollLeft;
|
|
2183
|
+
scrollPosition.top = target.documentElement.scrollTop;
|
|
2184
|
+
}
|
|
2185
|
+
sendScrollEvent("scroll", scrollPosition);
|
|
2186
|
+
}
|
|
2187
|
+
}
|
|
2188
|
+
|
|
2189
|
+
function getOffset(target) {
|
|
2190
|
+
if(target.offsetParent) {
|
|
2191
|
+
var newTarget = target.offsetParent;
|
|
2192
|
+
var offsetSum = getOffset(newTarget);
|
|
2193
|
+
return {
|
|
2194
|
+
left: offsetSum.left + target.offsetLeft,
|
|
2195
|
+
top: offsetSum.top + target.offsetTop
|
|
2196
|
+
}
|
|
2197
|
+
} else {
|
|
2198
|
+
return {
|
|
2199
|
+
left: target.offsetLeft,
|
|
2200
|
+
top: target.offsetTop
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
}
|
|
2204
|
+
|
|
2205
|
+
function sendMouseEvent(event, eventType) {
|
|
2206
|
+
var message = {};
|
|
2207
|
+
message.type = "iframe";
|
|
2208
|
+
message.event = {};
|
|
2209
|
+
message.event.type = eventType;
|
|
2210
|
+
message.event.clientX = event.clientX;
|
|
2211
|
+
message.event.clientY = event.clientY;
|
|
2212
|
+
|
|
2213
|
+
window.parent.postMessage(JSON.stringify(message), "*");
|
|
2214
|
+
}
|
|
2215
|
+
|
|
2216
|
+
function sendChangeEvent(eventType, target, eventLocation) {
|
|
2217
|
+
var message = {};
|
|
2218
|
+
message.type = "iframe";
|
|
2219
|
+
message.event = {};
|
|
2220
|
+
message.event.type = eventType;
|
|
2221
|
+
message.event.value = target.value;
|
|
2222
|
+
message.event.location = eventLocation;
|
|
2223
|
+
|
|
2224
|
+
window.parent.postMessage(JSON.stringify(message), "*");
|
|
2225
|
+
}
|
|
2226
|
+
|
|
2227
|
+
function sendKeyboardEvent(eventType, keyCode, eventLocation) {
|
|
2228
|
+
var message = {};
|
|
2229
|
+
message.type = "iframe";
|
|
2230
|
+
message.event = {};
|
|
2231
|
+
message.event.type = eventType;
|
|
2232
|
+
message.event.keyCode = keyCode;
|
|
2233
|
+
message.event.location = eventLocation;
|
|
2234
|
+
|
|
2235
|
+
window.parent.postMessage(JSON.stringify(message), "*");
|
|
2236
|
+
}
|
|
2237
|
+
|
|
2238
|
+
function sendScrollEvent(eventType, scrollPosition) {
|
|
2239
|
+
var message = {};
|
|
2240
|
+
message.type = "iframe";
|
|
2241
|
+
message.event = {};
|
|
2242
|
+
message.event.type = eventType;
|
|
2243
|
+
message.event.scrollPosition = scrollPosition;
|
|
2244
|
+
|
|
2245
|
+
window.parent.postMessage(JSON.stringify(message), "*");
|
|
2246
|
+
}
|
|
2247
|
+
|
|
2248
|
+
function engageMessage(message) {
|
|
2249
|
+
// *** EVOKE FIX FOR VEEVA BUG
|
|
2250
|
+
// var data = JSON.parse(message.data);
|
|
2251
|
+
var data = typeof message.data == 'string' ? JSON.parse(message.data) : message.data;
|
|
2252
|
+
// ***
|
|
2253
|
+
|
|
2254
|
+
if(data.type && data.type === "events") {
|
|
2255
|
+
internalMessage = true;
|
|
2256
|
+
|
|
2257
|
+
// Get scrolling offset
|
|
2258
|
+
var scrollX = 0;
|
|
2259
|
+
var scrollY = 0;
|
|
2260
|
+
if(document.scrollingElement) {
|
|
2261
|
+
scrollX = document.scrollingElement.scrollLeft;
|
|
2262
|
+
scrollY = document.scrollingElement.scrollTop;
|
|
2263
|
+
} else if(document.documentElement) {
|
|
2264
|
+
scrollX = document.documentElement.scrollLeft;
|
|
2265
|
+
scrollY = document.documentElement.scrollTop;
|
|
2266
|
+
}
|
|
2267
|
+
|
|
2268
|
+
if(data.event.type === "change") {
|
|
2269
|
+
data.event.location.x -= scrollX;
|
|
2270
|
+
data.event.location.y -= scrollY;
|
|
2271
|
+
|
|
2272
|
+
if(frameScale) {
|
|
2273
|
+
data.event.location.x *= frameScale;
|
|
2274
|
+
data.event.location.y *= frameScale;
|
|
2275
|
+
}
|
|
2276
|
+
|
|
2277
|
+
var target = document.elementFromPoint(data.event.location.x, data.event.location.y);
|
|
2278
|
+
if(target) {
|
|
2279
|
+
simulateChangeEvent(target, data);
|
|
2280
|
+
}
|
|
2281
|
+
} else if(data.event.type === "keypress") {
|
|
2282
|
+
data.event.location.x -= scrollX;
|
|
2283
|
+
data.event.location.y -= scrollY;
|
|
2284
|
+
|
|
2285
|
+
if(frameScale) {
|
|
2286
|
+
data.event.location.x *= frameScale;
|
|
2287
|
+
data.event.location.y *= frameScale;
|
|
2288
|
+
}
|
|
2289
|
+
|
|
2290
|
+
var target = document.elementFromPoint(data.event.location.x, data.event.location.y);
|
|
2291
|
+
if(target) {
|
|
2292
|
+
simulateKeypressEvent(target, data);
|
|
2293
|
+
}
|
|
2294
|
+
} else if(data.event.type === "scroll") {
|
|
2295
|
+
simulateScrollEvent(data);
|
|
2296
|
+
} else {
|
|
2297
|
+
var target = document.elementFromPoint(data.event.clientX, data.event.clientY);
|
|
2298
|
+
if(target) {
|
|
2299
|
+
simulateMouseEvent(target, data);
|
|
2300
|
+
}
|
|
2301
|
+
}
|
|
2302
|
+
} else if(data.type && data.type === "scale") {
|
|
2303
|
+
if(typeof data.value === "number" && data.value > 0) {
|
|
2304
|
+
frameScale = data.value;
|
|
2305
|
+
}
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
|
|
2309
|
+
function simulateChangeEvent(target, data) {
|
|
2310
|
+
target.value = data.event.value;
|
|
2311
|
+
var evt = htmlEvent(data.event.type);
|
|
2312
|
+
dispatchEvent(target, evt, data.event.type);
|
|
2313
|
+
}
|
|
2314
|
+
|
|
2315
|
+
function simulateKeypressEvent(target, data) {
|
|
2316
|
+
//Treat the keypress event as a click event since keypress event does not work in some content
|
|
2317
|
+
var evt = mouseEvent("click", 0, 0, data.event.location.x, data.event.location.y);
|
|
2318
|
+
dispatchEvent(target, evt, "click");
|
|
2319
|
+
}
|
|
2320
|
+
|
|
2321
|
+
function simulateScrollEvent(data) {
|
|
2322
|
+
var scrollPosition = data.event.scrollPosition;
|
|
2323
|
+
|
|
2324
|
+
if(document.scrollingElement) {
|
|
2325
|
+
document.scrollingElement.scrollLeft = scrollPosition.left;
|
|
2326
|
+
document.scrollingElement.scrollTop = scrollPosition.top;
|
|
2327
|
+
} else if(document.documentElement) {
|
|
2328
|
+
document.documentElement.scrollLeft = scrollPosition.left;
|
|
2329
|
+
document.documentElement.scrollTop = scrollPosition.top;
|
|
2330
|
+
}
|
|
2331
|
+
}
|
|
2332
|
+
|
|
2333
|
+
function simulateMouseEvent(target, data) {
|
|
2334
|
+
var evt = mouseEvent(data.event.type, 0, 0, data.event.clientX, data.event.clientY);
|
|
2335
|
+
dispatchEvent(target, evt, data.event.type);
|
|
2336
|
+
}
|
|
2337
|
+
|
|
2338
|
+
function htmlEvent(type) {
|
|
2339
|
+
var evt;
|
|
2340
|
+
var e = {
|
|
2341
|
+
bubbles: true,
|
|
2342
|
+
cancelable: true
|
|
2343
|
+
};
|
|
2344
|
+
if (typeof( document.createEvent ) == "function") {
|
|
2345
|
+
evt = document.createEvent("HTMLEvents");
|
|
2346
|
+
evt.initEvent(type, e.bubbles, e.cancelable);
|
|
2347
|
+
} else if (document.createEventObject) {
|
|
2348
|
+
evt = document.createEventObject();
|
|
2349
|
+
evt.eventType = type;
|
|
2350
|
+
for (prop in e) {
|
|
2351
|
+
evt[prop] = e[prop];
|
|
2352
|
+
}
|
|
2353
|
+
}
|
|
2354
|
+
return evt;
|
|
2355
|
+
}
|
|
2356
|
+
|
|
2357
|
+
function mouseEvent(type, sx, sy, cx, cy) {
|
|
2358
|
+
var evt;
|
|
2359
|
+
var e = {
|
|
2360
|
+
bubbles: true,
|
|
2361
|
+
cancelable: (type != "mousemove"),
|
|
2362
|
+
view: window,
|
|
2363
|
+
detail: 0,
|
|
2364
|
+
screenX: sx,
|
|
2365
|
+
screenY: sy,
|
|
2366
|
+
clientX: cx,
|
|
2367
|
+
clientY: cy,
|
|
2368
|
+
ctrlKey: false,
|
|
2369
|
+
altKey: false,
|
|
2370
|
+
shiftKey: false,
|
|
2371
|
+
metaKey: false,
|
|
2372
|
+
button: 0,
|
|
2373
|
+
relatedTarget: undefined
|
|
2374
|
+
};
|
|
2375
|
+
if (typeof( document.createEvent ) == "function") {
|
|
2376
|
+
evt = document.createEvent("MouseEvents");
|
|
2377
|
+
evt.initMouseEvent(type,
|
|
2378
|
+
e.bubbles, e.cancelable, e.view, e.detail,
|
|
2379
|
+
e.screenX, e.screenY, e.clientX, e.clientY,
|
|
2380
|
+
e.ctrlKey, e.altKey, e.shiftKey, e.metaKey,
|
|
2381
|
+
e.button, document.body.parentNode);
|
|
2382
|
+
} else if (document.createEventObject) {
|
|
2383
|
+
evt = document.createEventObject();
|
|
2384
|
+
for (prop in e) {
|
|
2385
|
+
evt[prop] = e[prop];
|
|
2386
|
+
}
|
|
2387
|
+
evt.button = { 0:1, 1:4, 2:2 }[evt.button] || evt.button;
|
|
2388
|
+
}
|
|
2389
|
+
return evt;
|
|
2390
|
+
}
|
|
2391
|
+
|
|
2392
|
+
function dispatchEvent (el, evt, type) {
|
|
2393
|
+
if (el.dispatchEvent) {
|
|
2394
|
+
el.dispatchEvent(evt);
|
|
2395
|
+
} else if (el.fireEvent) {
|
|
2396
|
+
el.fireEvent('on' + type, evt);
|
|
2397
|
+
}
|
|
2398
|
+
return evt;
|
|
2399
|
+
}
|
|
2400
|
+
|
|
2401
|
+
|
|
2402
|
+
};
|
|
2403
|
+
|
|
2404
|
+
|
|
2405
|
+
//support functions to allow Windows Modern to support the OnExit functions
|
|
2406
|
+
com_veeva_clm_createRecordsOnExit = function() {
|
|
2407
|
+
return com.veeva.clm.createRecordsOnExit();
|
|
2408
|
+
}
|
|
2409
|
+
com_veeva_clm_updateRecordsOnExit = function() {
|
|
2410
|
+
return com.veeva.clm.updateRecordsOnExit();
|
|
2411
|
+
}
|
|
2412
|
+
com_veeva_clm_updateCurrentRecordsOnExit = function() {
|
|
2413
|
+
return com.veeva.clm.updateCurrentRecordsOnExit();
|
|
2414
|
+
}
|
|
2415
|
+
|
|
2416
|
+
|
|
2417
|
+
com.veeva.clm.initialize();
|