-
Notifications
You must be signed in to change notification settings - Fork 0
/
trackShopifyFieldUpdates_UE.js
60 lines (55 loc) · 2.07 KB
/
trackShopifyFieldUpdates_UE.js
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
/**
* @NApiVersion 2.x
* @NScriptType UserEventScript
*
* Description:
* This script updates a custom date field, 'custrecord_last_product_info_updated', on an item record whenever specified fields are changed. It is triggered during the 'afterSubmit' event of record creation or editing.
*
* Purpose:
* To maintain an accurate timestamp of when critical product information was last updated, facilitating efficient data synchronization with external systems.
*
* Modules Required:
* - N/record: Used to interact with NetSuite records and perform updates.
*
* Trigger:
* - After Submit: Executes after a record is created or edited.
*
* Fields Monitored:
* - field1
* - field2
* - field3
*
* Logic:
* 1. The script checks if the current operation is a record creation or edit.
* 2. It compares the new and old values of specified fields.
* 3. If any monitored field has changed, it updates the 'custrecord_last_product_info_updated' field with the current date and time.
*/
define(['N/record'], function(record) {
function afterSubmit(context) {
// Exit if not a create or edit operation
if (context.type !== context.UserEventType.CREATE && context.type !== context.UserEventType.EDIT) {
return;
}
var newRecord = context.newRecord;
var oldRecord = context.oldRecord;
// List of fields to monitor for changes
var fieldsToMonitor = ['field1', 'field2', 'field3'];
// Check if any monitored field has changed
var shouldUpdateDate = fieldsToMonitor.some(function(fieldId) {
return newRecord.getValue(fieldId) !== oldRecord.getValue(fieldId);
});
// Update the custom date field if changes are detected
if (shouldUpdateDate) {
record.submitFields({
type: newRecord.type,
id: newRecord.id,
values: {
custrecord_last_product_info_updated: new Date()
}
});
}
}
return {
afterSubmit: afterSubmit
};
});