-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcen_jlo_cs_so_location_update.js
More file actions
70 lines (61 loc) · 2.69 KB
/
cen_jlo_cs_so_location_update.js
File metadata and controls
70 lines (61 loc) · 2.69 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
/= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =\
* Purpose:
* VER DATE AUTHOR CHANGES
* 1.0 November 6, 2023 Centric Consulting(Pradeep) Initial Version
\= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */
// Register the beforeSubmit function
define(['N/record', 'N/runtime', 'N/search'], function (record, runtime, search) {
function validateLine(scriptContext) {
log.debug("validate line");
try {
var corporateLocation = runtime.getCurrentScript().getParameter({name: 'custscript_cen_jlo_corp_loc2'});
//var corporateLocation = 2;
var newRecord = scriptContext.currentRecord;
var sublistName = scriptContext.sublistId;
// get the location from the header, this will be used for defaulting.
var locationIdHeader = newRecord.getValue({ fieldId: 'location'});
log.debug("location",locationIdHeader);
var locationLine = newRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'location'
});
log.debug("locatin",locationLine);
// this custom field is set on the line level for any lines
// that are actual items. If it is not set, then it is something like
// shopify discount line, shopify shipping cost
var orderLineId = newRecord.getCurrentSublistValue({
sublistId: 'item',
fieldId: 'custcol_celigo_etail_order_line_id'
});
// if the location is not set at the line level, then:
// if the line has the custcol_celigo_etail_order_line_id set, default the location from the header
// otherwise default to the corporate address
if (!locationLine) {
if (orderLineId) {
newRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'location',
value: locationIdHeader,
ignoreFieldChange: true
});
} else {
newRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'location',
value: corporateLocation,
ignoreFieldChange: true
});
}
}
return true;
} catch (e) {
log.error(e,e.message);
}
}
return {
validateLine: validateLine
};
});