forked from headintheclouddev/typings-suitescript-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example-ClientScript.ts
34 lines (30 loc) · 1.4 KB
/
example-ClientScript.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
/**
* @NAPIVersion 2.0
* @NScriptType ClientScript
*/
import {EntryPoints} from 'N/types'
import search = require('N/search');
export function pageInit(ctx: EntryPoints.Client.pageInitContext) {
if (ctx.mode != 'edit') return;
const customerId = ctx.currentRecord.getValue('entity'); // Assume this script is running on a transaction
search.lookupFields.promise({ type: 'customer', id: customerId, columns: ['companyname', 'datecreated', 'entitystatus'] }).then((values) => {
const name = values.companyname as string;
const date = values.datecreated as string;
const status = values.entitystatus as { value: string, text: string }[];
console.log('Customer', name, 'created at', date, 'status', status);
});
search.create.promise({
type: 'customer',
filters: [search.createFilter({ name: 'companyname', operator: search.Operator.ISNOTEMPTY })],
columns: [ // Not generally recommended to mix column creation formats like this, but it is technically acceptable. This demonstrates different ways to do it:
search.createColumn({ name: 'companyname', sort: search.Sort.ASC }),
{ name: 'email' },
'fax',
],
}).then(search => {
return search.run().getRange.promise({ start: 0, end: 1 });
}).then(results => {
if (results.length === 0) return alert("No companies");
alert(`First company alphabetically: ${results[0].getValue('companyname')}`);
});
}