-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathiii_cl_coupon_code_checkbox.js
55 lines (51 loc) · 1.76 KB
/
iii_cl_coupon_code_checkbox.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(['N/record'], function(record) {
function pageInit(context) {
var customer = context.currentRecord;
var numLines = customer.getLineCount({
sublistId: 'recmachcustomrecord_iii_prod_pref_item'
});
alert('This customer has ' + numLines + ' product preferences');
}
function fieldChanged(context) {
var customer = context.currentRecord;
var fieldId = context.fieldId;
if (fieldId === 'custentity_iii_apply_coupon') {
var couponCode = customer.getField('custentityiii_coupon_code');
couponCode.isDisabled = !customer.getValue(context.fieldId);
// TODO: Used to work, now doesn't, investigate
// customer.setValue(couponCode.isDisabled, !customer.getValue(context.fieldId));
if (couponCode.isDisabled) {
customer.setValue(couponCode.id, '');
}
}
}
function validateField(context) {
var customer = context.currentRecord;
var applyCoupon = customer.getValue('custentity_iii_apply_coupon');
if (applyCoupon) {
var couponCodeValue = customer.getValue('custentityiii_coupon_code');
var valueLength = couponCodeValue.length;
if (valueLength !== 5) {
alert('Please enter a coupon code with 5 characters.');
return false;
}
}
return true;
}
function saveRecord(context) {
const fieldIsValid = validateField(context);
if (!fieldIsValid) {
return false;
}
return true;
}
return {
pageInit: pageInit,
fieldChanged: fieldChanged,
saveRecord: saveRecord
}
});