-
Notifications
You must be signed in to change notification settings - Fork 0
/
workflow_action_script.ts
59 lines (49 loc) · 1.31 KB
/
workflow_action_script.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
/**
* @NApiVersion 2.x
* @NScriptType WorkflowActionScript
* @NModuleScope public
*/
import { EntryPoints } from 'N/types';
import * as record from 'N/record';
import * as log from 'N/log';
import * as https from 'N/https';
/**
* A workflow action script to post a webhook about the event.
*/
const postWebhook = (url: string, data: object) => {
const response = https.post({
url: url,
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
});
log.debug({
title: 'WEBHOOK RESPONSE',
details: response.body
});
};
export const onAction: EntryPoints.WorkflowAction.onAction = (
context: EntryPoints.WorkflowAction.onActionContext
) => {
const currentRecord = context.newRecord;
const recordId = currentRecord.id;
const recordType = currentRecord.type;
const eventDate = new Date().toISOString();
// Define the webhook URL
const webhookUrl = 'https://example.com/webhook-endpoint';
// Prepare the data to be sent to the webhook
const webhookData = {
event: 'Order Created',
recordId: recordId,
recordType: recordType,
eventDate: eventDate
};
// Post the webhook
postWebhook(webhookUrl, webhookData);
log.debug({
title: 'WEBHOOK POSTED',
details: `Record ID: ${recordId}, Record Type: ${recordType}`
});
return true;
};