-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateTransferOrder.ts
73 lines (65 loc) · 1.53 KB
/
createTransferOrder.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
/**
* @NApiVersion 2.1
* @NModuleScope Public
*/
import * as record from 'N/record';
import * as log from 'N/log';
/**
* A custom module to create a transfer order.
*/
export const create = (
toLocation: string,
fromLocation: string,
items: {
id: number;
quantityNeeded: number;
}[],
memo: string
) => {
log.debug({
title: 'CREATING TRANSER ORDER WITH ITEMS',
details: JSON.stringify(items),
});
const transferOrder = record.create({
type: record.Type.TRANSFER_ORDER,
isDynamic: true,
});
transferOrder.setValue('trandate', new Date());
transferOrder.setValue('memo', memo);
// order status - use default (Pending Fulfillment)
// incoterm - use default (DAP)
transferOrder.setValue('location', fromLocation);
transferOrder.setValue('transferlocation', toLocation);
items.map(function (item) {
// select new line
transferOrder.selectNewLine({
sublistId: 'item',
});
// set item
transferOrder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'item',
value: item.id,
});
// set quantity
transferOrder.setCurrentSublistValue({
sublistId: 'item',
fieldId: 'quantity',
value: item.quantityNeeded,
});
// commit line
transferOrder.commitLine({
sublistId: 'item',
});
});
// save record
const recordId = transferOrder.save({
enableSourcing: false,
ignoreMandatoryFields: false,
});
log.debug({
title: 'TRANSFER ORDER CREATED',
details: 'ID: ' + recordId,
});
return recordId;
};