I trying to modify a Purchase Order when a user opens it. This seems like this is a really simple example but doesn't seem to work. In the GUI I don't see the "test" memo. And in the script debug the memo field is empty.
I know the script is running because of the debug.
/**
* Update Drop Ship PO with route Information
*
* @author Patrick
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/
define(['N/search', 'N/record'],
function(search, record) {
function beforeLoad(context) {
var newRecord = context.newRecord;
newRecord.setValue({fieldId: 'memo', value: 'this is a test'});
log.debug({title: 'memo', details: newRecord.getValue({fieldId: 'memo'})});
return true;
}
return {
beforeLoad: beforeLoad
};
});
I am assuming it has something to do with the record I can modify but I can't for the life of me find a working example in the docs. Any help would be greatly appreciated.
I trying to modify a Purchase Order when a user opens it. This seems like this is a really simple example but doesn't seem to work. In the GUI I don't see the "test" memo. And in the script debug the memo field is empty.
I know the script is running because of the debug.
/**
* Update Drop Ship PO with route Information
*
* @author Patrick
* @NApiVersion 2.0
* @NScriptType UserEventScript
*/
define(['N/search', 'N/record'],
function(search, record) {
function beforeLoad(context) {
var newRecord = context.newRecord;
newRecord.setValue({fieldId: 'memo', value: 'this is a test'});
log.debug({title: 'memo', details: newRecord.getValue({fieldId: 'memo'})});
return true;
}
return {
beforeLoad: beforeLoad
};
});
I am assuming it has something to do with the record I can modify but I can't for the life of me find a working example in the docs. Any help would be greatly appreciated.
Share Improve this question edited May 14, 2019 at 22:00 Patrick_Finucane asked May 14, 2019 at 21:38 Patrick_FinucanePatrick_Finucane 7551 gold badge7 silver badges25 bronze badges2 Answers
Reset to default 5You cannot modify fields on existing records in beforeLoad
; see the Help page for beforeLoad
for details. Here's a snippet of beforeLoad
limitations:
- beforeLoad user events cannot be triggered when you load/access an online form.
- Data cannot be manipulated for records that are loaded in beforeLoad scripts. If you attempt to update a record loaded in beforeLoad, the logic is ignored.
- Data can be manipulated for records created in beforeLoad user events.
- Attaching a child custom record to its parent or detaching a child custom record from its parent triggers an edit event.
The second bullet point is the relevant one for your issue.
newRecord.setValue
wont work in beforeLoad. Its better if you use newRecord.submitFields
like below
record.submitFields({
id: newRecord.id,
type: newRecord.type,
values: {'memo': 'this is a test'}
});
Hope it helps!!