-
Notifications
You must be signed in to change notification settings - Fork 0
/
ebay_order_workflow_action.ts
90 lines (86 loc) · 2.33 KB
/
ebay_order_workflow_action.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
/**
* @NApiVersion 2.x
* @NScriptType WorkflowActionScript
* @NModuleScope public
*
*/
import { EntryPoints } from 'N/types';
/**
* A workflow action script to add a black comb to eBay orders.
*/
export const onAction: EntryPoints.WorkflowAction.onAction = (
context: EntryPoints.WorkflowAction.onActionContext
) => {
const salesRecord = context.newRecord;
// ebay
if (salesRecord.getValue('custbody_fa_channel') === 'eBay') {
// check if already in order production: 30457 / SB: 30559
const lines = salesRecord.getLineCount({ sublistId: 'item' });
let add_comb = true;
let quantity = 0;
for (let i = 0; i < lines; i++) {
const id = salesRecord.getSublistValue({
sublistId: 'item',
fieldId: 'custcol_sp_item_id',
line: i,
});
if (Number(id) === 30457) {
add_comb = false;
} else {
quantity =
quantity +
Number(
salesRecord.getSublistValue({
sublistId: 'item',
fieldId: 'quantity',
line: i,
})
);
}
}
// add black comb to order
if (add_comb) {
// set item, quantity, price level, price, description & tax code
salesRecord.selectNewLine({ sublistId: 'item' });
salesRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: 30457, // black comb
fireSlavingSync: true,
});
salesRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: Number(quantity),
fireSlavingSync: true,
});
salesRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'price',
value: -1,
fireSlavingSync: true,
});
salesRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'amount',
value: 0,
fireSlavingSync: true,
});
salesRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'description',
value: 'Black Unbreakable Comb',
fireSlavingSync: true,
});
salesRecord.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'taxcode',
value: -7,
fireSlavingSync: true,
});
salesRecord.commitLine({ sublistId: 'item' });
}
return true;
}
return false;
};