5

我无法使用 SuiteScript 2.0 设置 INLINEHTML 类型的字段。但是,相同的字段适用于 SuiteScript 1.0。这是代码片段:

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
// In SuiteScript 2.0   
define(['N/search'], function(search) {
    return {
        pageInit: function(context) {
            var currentRecord = context.currentRecord;
            // Set Value (This does not set any data)
            currentRecord.setValue({ fieldId: 'inline_html_field', value: '<div>Test Value</div>' });
            // Get value (Returns undefined)
            currentRecord.getValue({ fieldId: 'inline_html_field'});
        }
    }
});

// In SuiteScript 1.0
nlapiGetFieldValue('inline_html_field'); // Returns the data in field
4

6 回答 6

1

我有类似的问题,您需要使用 suitescript 1.0 来操作 NetSuite 中的内联 html 字段。但是,您可以使用以下命令,而不是将整个代码从 suitescript 2.0 转换为 1.0:

window.nlapiSetFieldValue('YOUR_FIELDID', '<a>YOUR HTML CONTENT</a>');

通过放置窗口。您可以在suitescript 2.0 中使用任何suitescript 1.0 api!

于 2018-08-01T23:16:03.140 回答
1

不幸的是,这是一个实例,在 SS 2.0 中的 record.getValue() 或 currentRecord.getValue() 背后实现的逻辑存在缺陷。在 SS 1.0 中,nlapiGetFieldValue() 通过的验证比 SS 2.0 对应的要少。这是一个示例(希望 NetSuite 不会因为侵犯他们的 IP 而让我入狱)。这就是您请求值时发生的情况。

function getTheValue(options)
        {
            var fieldId;

            fieldId = '....';// Do a bunch of logic to validate the options parameter is correct

            return doGetTheValue(fieldId);
        }

        function doGetTheValue(fieldId)
        {
            var fieldObj = goodOlegetField(fieldId); // goodOle being our 1.0 api prefix....
            // the function call above returns null preventing your request from succeeding.
            var value;
            if (fieldObj == null)
                return undefined;


        }

我希望这是有道理的,虽然这不是一个答案,但它会提供关于为什么你会得到你得到的回应的洞察力。这也是你没有疯的可靠验证。在使用 SS 2.0 时,我经常发现我需要这种保证。

于 2017-08-31T18:09:29.740 回答
0

最近,我尝试使用 UserEvent ScriptType 设置一个 INLINEHTML 类型的字段,它可以工作。ClientScript 只能在编辑记录时工作。

于 2019-12-26T02:49:03.717 回答
0

我认为您需要 currentRecord 模块。

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 */
// In SuiteScript 2.0   
define(['N/search', 'N/currentRecord'], function(search, currentRecord) {
    return {
        pageInit: function(context) {
            var currentRecord = context.currentRecord;
            // Set Value (This does not set any data)
            currentRecord.setValue({ fieldId: 'inline_html_field', value: '<div>Test Value</div>' });
            // Get value (Returns undefined)
            currentRecord.getValue({ fieldId: 'inline_html_field'});
        }
    }
});
于 2017-08-30T00:34:56.627 回答
0

在处理内联 html 字段时,我只是将它们视为客户端的普通 html。为了避免问题,我通常会有一个默认值

// User Event Before Load
nlapiSetFieldValue('custbody_inline_field', '<div id="myuniqueid">default content</div>');

或者

var fld = form.addField('custpage_inline_field'...); // look up field creation in the help.
fld.setDefaultValue('<div id="myuniqueid">default content</div>');

然后在客户端只操作 $("#myuniqueid") 的内容。您不必使用 jQuery,但它现在包含在 NS GUI 中。

于 2017-09-01T21:13:23.833 回答
0

使用它可能会有所帮助:

var val = currentRecord.getValue({ fieldId: 'inline_html_field'});
log.debug({title:test,details:JSON.stringify(val);})
于 2018-08-24T13:52:58.967 回答