Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
421 views
in Technique[技术] by (71.8m points)

netsuite - SS2.0 Display Message on Record

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Since the release 2018.2 they added a new method in N/ui/serverWidget module named Form.addPageInitMessage(options) and does exactly what OP wanted to do.

Given the example above it should look something like this.

/**
 *@NApiVersion 2.0
 *@NScriptType UserEventScript
*/
define(['N/ui/serverWidget', 'N/record'],
    function(serverWidget, record) {
        function beforeLoad(context) {

          var rec = context.newRecord;
          var status = rec.getValue('status');
          if (status === 'Unapproved Payment') {
           var myMsg = mess.create({
                title: "PAYMENT ERROR",
                message: status,
                type: mess.Type.ERROR,
                duration: 500000
           });
           context.form.addPageInitMessage({message: myMsg});
        }

    return {
        beforeLoad: beforeLoad 
    };
});

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...