-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuser_task_client.ts
83 lines (73 loc) · 1.94 KB
/
user_task_client.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
/**
*@NApiVersion 2.x
*@NScriptType ClientScript
*/
import { EntryPoints } from 'N/types';
import * as currentRecord from 'N/currentRecord';
import * as record from 'N/record';
import * as dialog from 'N/ui/dialog';
/**
* A client script to update customer record on task completion.
*/
export const pageInit: EntryPoints.Client.pageInit = () => {
console.log('Task Client Script Loaded');
};
export const completeUpdateCustomer = () => {
const task = currentRecord.get();
const customer = task.getValue('company');
// load & update customer
if (customer != '') {
const customerId = updateCustomer(customer);
if (customerId) {
task.setValue({
fieldId: 'status',
value: 'COMPLETE',
});
// display alert
dialog.alert({
title: 'TASK SET TO COMPLETED',
message:
'This task has been completed and the customer has been updated. Please save to continue.',
});
} else {
dialog.alert({
title: 'UPDATE ERROR',
message: 'Customer update error. Please contact Admin.',
});
}
} else {
task.setValue({
fieldId: 'status',
value: 'COMPLETE',
});
dialog.alert({
title: 'TASK SET TO COMPLETED',
message: 'This task has been completed. Please save to continue.',
});
}
};
export const updateCustomer = (id: record.FieldValue) => {
const customerRecord = record.load({
type: 'customer',
id: id,
isDynamic: true,
});
const followUpScheduled = customerRecord.getValue(
'custentity_sp_follow_up_scheduled'
);
if (followUpScheduled) {
customerRecord.setValue({
fieldId: 'custentity_sp_last_follow_up_date',
value: new Date(),
});
customerRecord.setValue({
fieldId: 'custentity_sp_follow_up_scheduled',
value: false,
});
}
const customerId = customerRecord.save({
enableSourcing: false,
ignoreMandatoryFields: false,
});
return customerId;
};