-
Notifications
You must be signed in to change notification settings - Fork 0
/
agreements_client.ts
93 lines (87 loc) · 2.67 KB
/
agreements_client.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
import { EntryPoints } from 'N/types';
import * as currentRecord from 'N/currentRecord';
import * as record from 'N/record';
/**
* A client script to attach files to a customer record.
*/
export const pageInit: EntryPoints.Client.pageInit = () => {
console.log('Agreements Client Script Loaded...');
};
export const fieldChanged: EntryPoints.Client.fieldChanged = (
context: EntryPoints.Client.fieldChangedContext
) => {
const currentRecord = context.currentRecord;
const fieldName = context.fieldId;
const value = currentRecord.getValue(fieldName);
console.log(`changed field: ${fieldName}`);
if (fieldName === 'custpage_customer' && value !== '') {
// check if is a valid internal id (number)
if (isNaN(Number(value))) {
alert(`${value} is not a valid internal id.`);
currentRecord.setValue(fieldName, '');
} else {
// load record
try {
const customer = record.load({
type: 'customer',
id: value,
});
alert(
`You have entered the internal id for customer: ${customer.getValue(
'entityid'
)}`
);
} catch (e) {
alert(e.message);
}
}
}
};
export const sublistChanged: EntryPoints.Client.sublistChanged = (
context: EntryPoints.Client.sublistChangedContext
) => {
// var currentRecord = context.currentRecord;
const sublistName = context.sublistId;
console.log(`changed sublist: ${sublistName}`);
};
export const saveRecord: EntryPoints.Client.saveRecord = () => {
const cr = currentRecord.get();
const lines = cr.getLineCount({ sublistId: 'custpage_agreements_sublist' });
let files = [];
for (let i = 0; i < lines; i++) {
const cb = cr.getSublistValue({
sublistId: 'custpage_agreements_sublist',
fieldId: 'custpage_result_checkbox',
line: i,
});
const fileId = cr.getSublistValue({
sublistId: 'custpage_agreements_sublist',
fieldId: 'custpage_result_fileid',
line: i,
});
if (cb) {
files.push(fileId);
}
}
const customer = cr.getValue('custpage_customer');
if (customer !== '' && files.length > 0) {
console.log(`Setting custpage_files: ${files.toString()}`);
cr.setValue('custpage_files', files.toString());
return true;
} else {
if (files.length === 0 && customer) {
alert('Please select at least one file to attach.');
} else if (customer === '' && files.length > 0) {
alert('Please enter the customers internal id to continue.');
} else {
alert(
'Please enter the customers internal id and select at least one file to attach.'
);
}
return false;
}
};