-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathset_po_item_status_scheduled.js
105 lines (105 loc) · 4.58 KB
/
set_po_item_status_scheduled.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
define(['N/search', 'N/record'], function(search, record){
/**
* @NApiVersion 2.x
* @NScriptType ScheduledScript
*/
function execute(scriptContext) {
var poSearch = search.load({ //searches for all POs
id: 'customsearchpo_id'
});
poSearch.run().each(function(result){
if(result != null && result != ''){
var internalid = result.getValue({
name: "internalid"
});
var poRecord = record.load({ //loads the PO record
type: record.Type.PURCHASE_ORDER,
id: internalid
});
for (var i = 0; i < poRecord.getLineCount('item'); i++){ //execute for every item line in the PO
var quantityBilled = poRecord.getSublistValue({ //get PO item's quantities
sublistId: 'item',
fieldId: 'quantitybilled',
line: i
});
var quantityRec = poRecord.getSublistValue({
sublistId: 'item',
fieldId: 'quantityreceived',
line: i
});
var quantity = poRecord.getSublistValue({
sublistId: 'item',
fieldId: 'quantity',
line: i
});
var isClosed = poRecord.getSublistValue({
sublistId: "item",
fieldId: "isclosed",
line: i
});
if(quantityRec >= quantity && quantityBilled >= quantity){ //set fully billed
poRecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcolitem_status',
line: i,
value: 2
});
}
if(isClosed == true){ //set closed
poRecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcolitem_status',
line: i,
value: 1
});
}
else if(quantityRec < quantity && quantityRec > 0 && quantityBilled < quantityRec){ //set pending billing/partially received
poRecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcolitem_status',
line: i,
value: 6
});
}
else if(quantityRec < quantity && quantityRec > 0 && quantityBilled >= quantityRec){ //set partially received
poRecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcolitem_status',
line: i,
value: 3
});
}
else if(quantityRec < quantity && quantityRec == 0){ //set pending receipt
poRecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcolitem_status',
line: i,
value: 5
});
}
else if(quantityRec >= quantity && quantityBilled < quantityRec){ //set pending billing
poRecord.setSublistValue({
sublistId: 'item',
fieldId: 'custcolitem_status',
line: i,
value: 4
});
}
else{
poRecord.setSublistTest({ //set blank
sublistId: 'item',
fieldId: 'custcolitem_status',
line: i,
value: ''
});
}
}
poRecord.save(false, false); //save changes to PO record
}
return true;
});
}
return {
execute: execute
}
});