Reputation: 1
/\*\*
* @NApiVersion 2.x
* @NScriptType UserEventScript
\*/
define(\['N/log', 'N/record'\],
function(log, record) {
function beforeSubmit(context) {
try {
// Get the new record from the context
var newRecord = context.newRecord;
// Check if the 'consoldaysoverdue' field has changed
if (context.type === context.UserEventType.EDIT && newRecord.isFieldChanged({
fieldId: 'consoldaysoverdue'
})) {
// Hide popup notifications for the 'consoldaysoverdue' field
newRecord.setField({
fieldId: 'suppressFieldRecalculation',
value: true
});
}
} catch (e) {
// Log any errors
log.error({
title: 'Error Hiding Popup Notification',
details: e.toString(),
});
}
}
return {
beforeSubmit: beforeSubmit,
};
}
);
I've tried changing the script type to Client Script. And I get another error message that it must be a UserEvent Type. The function of this code is to eliminate the "Consolidated days due" pop up notification that keeps appearing on customer forms.
Upvotes: 0
Views: 151
Reputation: 21
There are quite a few things to change in your code.
Besides the obvious change of @NScriptType
to UserEventScript
already suggested by @bknights, you need to implement the correct entry points. See NetSuite's help page and look at the entry point fieldChanged
. Note that the script context is completely different and oldRecord or newRecord do not exist there. You'll have to rewrite most of the script to adapt...
You also seem to be uploading the script file over an existing file that's already linked to the UE script. Try uploading with a new file name, or deleting the previous script record and source code file.
Finally, there seem to be some lingering backslashes (\
) around your code pasted above, make sure they are not in the actual .js
file.
Try this (untested)
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define([
'N/log',
], (
log,
) => {
function fieldChanged(context) {
try {
if (context.fieldId === 'consoldaysoverdue') {
// Hide popup notifications for the 'consoldaysoverdue' field
context.currentRecord.setValue({
fieldId: 'suppressFieldRecalculation',
value: true
});
}
} catch (e) {
log.error({
title: 'Error Hiding Popup Notification',
details: e.toString(),
});
}
}
return {
fieldChanged: fieldChanged,
};
});
Upvotes: 1
Reputation: 15447
Regarding your error you likely have to delete the script before you can upload a file with a changed script type. i.e. If you first uploaded your file with
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
and then defined a script you'd have to delete the script in order to change the script type defined in the file.
However given what you are trying to do a ClientScript
is the way to go.
Upvotes: 1