forked from headintheclouddev/typings-suitescript-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample-UserEventScript.ts
More file actions
23 lines (20 loc) · 904 Bytes
/
example-UserEventScript.ts
File metadata and controls
23 lines (20 loc) · 904 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
/**
* @NAPIVersion 2.1
* @NScriptType UserEventScript
*/
import type {EntryPoints} from 'N/types';
import * as log from 'N/log';
import * as query from 'N/query';
// Let's assume this example is deployed to sales orders
export function beforeSubmit(context: EntryPoints.UserEvent.beforeSubmitContext) {
if (context.type == context.UserEventType.CREATE) {
const customerId = context.newRecord.getValue('entity') as string;
log.debug('beforeSubmit', `Submitting new transaction for entity: ${customerId}`); // When creating a transaction from an entity, log the entity internal id
// SuiteQL example
const results: { companyname: string }[] = query.runSuiteQL({
query: `SELECT companyName FROM customer WHERE id = ?`,
params: [customerId]
}).asMappedResults() as any;
log.debug('beforeSubmit', `Customer ${customerId} values: ${JSON.stringify(results)}`);
}
}