I'd like to use SS2.0 and the 'new' N/ui/message module to display warnings or errors when a user views a record. In reality, I'd like to understand how to run any 2.0 client script code on record view.
I managed an example I can run, which works from the console:
require(['N/currentRecord', 'N/ui/message'],
function(curr, mess) {
var rec = curr.get();
var status = rec.getValue('status');
if (status === 'Unapproved Payment') {
var myMsg = mess.create({
title: "PAYMENT ERROR",
message: status,
type: mess.Type.ERROR
}).show({
duration: 500000
});
}});
Runs fine in edit mode(pageInit or wherever) but haven't found a method to load and execute on 'View'. Is this even possible in 2.0? Do I have to use the 1.0 tricks still?
FWIW the following works in edit mode but not view mode. (See my other answer for a hack that works as of October 2016) I suspect this'll be fixed somewhere along the way since similar code has worked for years in SS1.0. If you have a business case please file a support case with Netsuite.
user event script:
with testSimpleClient being:
Based on help topic:
In view mode, you can only attach a user event script (beforeLoad).
N/currentRecord module only runs on client-side scripts which is why it didn't work.
Use N/record module instead.
so a working example. This is not good (not very portable and certainly not bundle friendly) but it works:
Server Side:
Client Side: