-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSP_CaseRecord.ts
71 lines (60 loc) · 1.98 KB
/
SP_CaseRecord.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
/**
*@NApiVersion 2.1
*@NScriptType Restlet
*/
import { EntryPoints } from 'N/types';
import * as record from 'N/record';
import * as error from 'N/error';
/**
* A RESTlet to add a note to a record.
*/
function doValidation(args: any, argNames: any, methodName: any) {
for (let i = 0; i < args.length; i++)
if (!args[i] && args[i] !== 0)
throw error.create({
name: 'MISSING_REQ_ARG',
message:
'Missing a required argument: [' +
argNames[i] +
'] for method: ' +
methodName,
});
}
export const post: EntryPoints.RESTlet.post = (context: any) => {
doValidation([context.recordType], ['recordtype'], 'POST');
var rec = record.create({
type: context.recordType,
isDynamic: true,
});
// Set values
rec.setValue('customform', Number(context.customForm));
rec.setValue('company', Number(context.company));
rec.setValue('profile', Number(context.profile));
rec.setValue('priority', Number(context.priority));
rec.setValue('status', Number(context.status));
rec.setValue('origin', Number(context.origin));
rec.setValue('category', Number(context.category));
rec.setValue('title', context.title);
rec.setValue('email', context.email);
rec.setValue('incomingmessage', context.incomingMessage);
rec.setValue('firstname', context.firstName);
rec.setValue('lastname', context.lastName);
rec.setValue('phone', context.phone);
rec.setValue('quicknote', context.quickNote);
// Save case record
const recordId = rec.save();
// Create note
const note = record.create({
type: record.Type.NOTE,
});
// Set values
note.setValue('activity', recordId);
note.setValue('title', 'Contact Details');
note.setValue('author', context.company);
const noteContent = `
Name: ${context.firstName} ${context.lastName} / Phone: ${context.phone} / Email: ${context.email} / Submitted By: ${context.email}`;
note.setValue('note', noteContent);
// Save note
note.save();
return String(recordId);
};