2017-08-29 64 views
1

我无法使用SuiteScript 2.0设置INLINEHTML类型的字段。但是,相同的字段适用于SuiteScript 1.0。 这里是代码片段:在SuiteScript 2.0中设置客户端脚本中的内嵌HTML字段

/** 
* @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 
+0

您是否正在动态创建此字段,还是生活在记录中的自定义字段? –

+0

这是自定义字段,可用于记录。 – tarunbandil

回答

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'}); 
     } 
    } 
}); 
+0

我添加了currentRecord模块,但它不起作用。 – tarunbandil

+0

你说得对。这不起作用。 看来你不能这样做。我将你的代码复制到了我的环境中,并得到了相同的结果。它不适用于内联HTML字段;它可以与其他字段类型一起工作。 – user3075978

0

不幸的是,这是一个实例,其中record.getValue(后面实现的))在SS 2.0逻辑或currentRecord.getValue(是有缺陷的。在SS 1.0中,与SS 2.0相比,nlapiGetFieldValue()通过的验证更少。这里是一个例子(希望有足够的改变,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时需要这种保证。

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中。

相关问题