-
Notifications
You must be signed in to change notification settings - Fork 0
/
curbside_fulfillment_action.ts
106 lines (96 loc) · 2.74 KB
/
curbside_fulfillment_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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/**
* @NApiVersion 2.x
* @NScriptType WorkflowActionScript
* @NModuleScope public
*
*/
import { EntryPoints } from 'N/types';
import * as email from 'N/email';
import * as record from 'N/record';
import * as render from 'N/render';
import * as log from 'N/log';
/**
* A workflow action script to email customers.
* If the order is for curbside pickup, in-store pickup,
* or will call, send an email to the customer.
*/
export const onAction: EntryPoints.WorkflowAction.onAction = (
context: EntryPoints.WorkflowAction.onActionContext
) => {
// shipping methods
const curbsidePickup = '31171';
const inStorePickup = '22004';
const willCall = '21989';
const itemFulfill = context.newRecord;
const shipMethod = itemFulfill.getValue('shipmethod') as string;
const customer = itemFulfill.getValue('entity') as number;
const shipStatus = itemFulfill.getValue('shipstatus') as string;
try {
// curbside
if (
shipMethod === curbsidePickup ||
shipMethod === inStorePickup ||
shipMethod === willCall
) {
let method: string;
let replyToEmail: string;
let bccList: number[];
let recipient: number;
if (shipMethod == willCall) {
replyToEmail = '[email protected]';
// load customer record
const customerRecord = record.load({
type: record.Type.CUSTOMER,
id: customer,
isDynamic: true,
});
// check for email
const customerEmail = customerRecord.getValue('email') as string;
if (customerEmail === '') {
method = 'Please Notify Customer | Will Call';
bccList = [207];
recipient = 73560;
} else {
method = 'Will Call';
bccList = [207, 73560];
recipient = customer;
}
} else {
method = 'Curbside Pickup';
replyToEmail = '[email protected]';
bccList = [207];
recipient = customer;
}
if (shipStatus == 'C') {
const mergeResult = render.mergeEmail({
templateId: 124,
entity: null,
recipient: null,
supportCaseId: null,
transactionId: itemFulfill.id,
customRecord: null,
});
const emailSubject = `
${method} Order ${itemFulfill.getValue('custbody_sp_order_number')}
`;
const emailBody = mergeResult.body;
email.send({
author: 264,
recipients: recipient,
replyTo: replyToEmail,
cc: bccList,
subject: emailSubject,
body: emailBody,
// @ts-ignore
transactionId: itemFulfill.id,
});
}
}
return true;
} catch (e) {
log.error({
title: 'Error:',
details: e.message,
});
}
};