如何使用SuiteScript在Netsuite中设置日期/时间字段

Ari*_*dag 2 javascript netsuite

var curRate = nlapiCreateRecord("customrecord_currency_exchange_rates",{recordmode: 'dynamic'});
        serverDt = "09/25/2013 06:00:01 am"
        var timezone = compConf.getFieldText('timezone');
        curRate.setDateTimeValue('custrecord_effective_date' ,serverDt ,timezone);


        nlapiSubmitRecord(curRate);
Run Code Online (Sandbox Code Playgroud)

您好,我尝试设置custrecord_effective_date字段,它是日期/时间类型。但是执行后会在下面显示错误。如何设置此字段?

感谢帮助。

INVALID_FLD_VALUE您为以下字段输入了无效的字段值09/25/2013 06:00:01 am:custrecord_effective_date

Dee*_*gan 6

用于使用 SuiteScript 2.O 设置日期/时间字段值。

  1. 首先使用“N/format”模块和“N/Record”模块。

  2. 创建一个普通的 Javascript 日期对象。

  3. 将日期对象格式化为日期时间对象。

  4. 并使用 Record.setValue() 方法设置日期时间值。

例子:

     var d = new Date();
     var formattedDateString = format.format({
                        value: d,
                        type: format.Type.DATETIMETZ
                        });

   record.setValue('yourDateTimeFieldId',formattedDateString );
Run Code Online (Sandbox Code Playgroud)


小智 5

尽管这是一篇过时的文章,并且最初的问题是关于SuiteScript 1.0的,但是我碰到了该页面,它在日期和时间字段中查找相同的INVALID_FLD_VALUE错误,但在SuiteScript 2.0中,并且由于解决方案最终有所不同,因此我想共享它给未来的读者。

在SuiteScript 2.0中,设置日期/时间字段仅需要一个JavaScript日期对象。以下是一个提交前用户事件上下文中的示例。

context.newRecord.setValue({
    fieldId : 'custrecord_myfield',
    value : new Date()
});
Run Code Online (Sandbox Code Playgroud)


bkn*_*hts 0

代码看起来不错 日期字段是否有任何限制,以至于您无法设置过去的日期?此外,您的 serverDt 与 Netsuite 帮助的值相同。复制干净了吗?如果您剪切该字符串并直接输入会发生什么?

最后,您确定您有一个日期时间字段而不是日期字段。如果我将您的代码应用于日期字段,我会收到相同的错误。