记录中的SS2.0显示消息 [英] SS2.0 Display Message on Record

查看:74
本文介绍了记录中的SS2.0显示消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用SS2.0和'new'N/ui/message模块在用户查看记录时显示警告或错误.实际上,我想了解如何在记录视图上运行任何2.0客户端脚本代码.

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
            });
        }});

在编辑模式(pageInit或任何地方)下均可正常运行,但未找到在视图"上加载和执行的方法.在2.0中甚至有可能吗?我还必须使用1.0技巧吗?

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?

推荐答案

是一个可行的示例.这不好(不是很轻便,当然也不是捆绑软件),但是它可以工作:

so a working example. This is not good (not very portable and certainly not bundle friendly) but it works:

服务器端:

/**
 *@NApiVersion 2.x
 *@NScriptType UserEventScript
 */
define(['N/record', 'N/log', 'N/ui/serverWidget'],
    function(record, log, ui) {
        function beforeLoad(context) {
            log.debug({title:'before load with '+ context.type +' on '+ context.form.title});
            if (context.type != 'view') return;
            log.debug({title:'setting client script'});

            var inline = context.form.addField({
                id:'custpage_trigger_it',
                label:'not shown',
                type: ui.FieldType.INLINEHTML,
            });
            inline.defaultValue = "jQuery(function($){ require(['/SuiteScripts/testSS2/testSimpleClient'], function(mod){ console.log('loaded'); mod.showMessage();});});</script>";



            //context.form.clientScriptModulePath = './testSimpleClient.js';
        }


    return {
        beforeLoad: beforeLoad 
    };
});

客户端:

define(['N/ui/message', 'N/currentRecord'], function(msg, currentRecord){
    window.console.log('processing script');
    function showMessage() {
        var rec = currentRecord.get();
        window.console.log('record status is '+ rec.getValue('status'));
        if('Pending Approval' == rec.getValue('status')){
            var myMsg = msg.create({
                title: "Not Committed",
                message: rec.getValue('status'), //'Please Approve',
                type: msg.Type.ERROR
            }).show({
                duration: 10000
            });
        }
    }



    return {
        showMessage:showMessage
    };
});

这篇关于记录中的SS2.0显示消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆