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

Hello I try to set custrecord_effective_date field which is a date/time type. But after the execution it gives an error below. How can I set this field?

thanks for help.

INVALID_FLD_VALUE You have entered an Invalid Field Value 09/25/2013 06:00:01 am for the following field: custrecord_effective_date

Arif Karadag
  • 129
  • 1
  • 2
  • 8

9 Answers9

9

Although this is an old post and the original question is about SuiteScript 1.0, I came across this page looking for the same INVALID_FLD_VALUE error with the date/time field but in SuiteScript 2.0, and since the solution ended up being different I wanted to share it for future readers.

In SuiteScript 2.0, setting a date/time field simply requires a JavaScript date object. Below is an example within a before submit user event context.

context.newRecord.setValue({
    fieldId : 'custrecord_myfield',
    value : new Date()
});
theark40
  • 319
  • 2
  • 5
5

For setting Date/Time Field values using SuiteScript 2.O.

  1. First Use 'N/format' module and 'N/Record' Module.

  2. Create a normal Javascript Date Object.

  3. Format the Date Object to DateTime Object.

  4. And use Record.setValue() method for setting the datetime value.

Example:

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

   record.setValue('yourDateTimeFieldId',formattedDateString );
Deepan Murugan
  • 721
  • 2
  • 19
  • 41
3

For anyone that may be stuck with a SuiteScript 1.0 script trying to populate a date/time field and the existing solutions don't work for you, you can try using NetSuites nlapiDateToString method. Apparently the date/time field wants a string.

Example:

var record = nlapiCreateRecord('your record type');
record .setFieldValue('your date field id', nlapiDateToString(new Date(), 'datetimetz'));
nlapiSubmitRecord(record, false, true);

The SuiteScript 1.0 reference for more detail:

enter image description here

CCC
  • 339
  • 2
  • 6
1

Hi thanks for answers after posting the question i checked the Form of record type and when i checked for the field 'custrecord_effective_date' I noticed that the date format must be 'DD/MM/YYYY HH:MM:SS' so when i changed it worked.

Arif Karadag
  • 129
  • 1
  • 2
  • 8
1

If you look at the NetSuite WSDL file, you will find the dateTime declaration:

<xs:simpleType name="dateTime" id="dateTime">
<xs:documentation
    source="http://www.w3.org/TR/xmlschema-2/#dateTime"/>

Go to the URL and look at the source:

3.2.7 dateTime

[Definition:] dateTime values may be viewed as objects with integer-valued year, month, day, hour and minute properties, a decimal-valued second property, and a boolean timezoned property. Each such object also has one decimal-valued method or computed property, timeOnTimeline, whose value is always a decimal number; the values are dimensioned in seconds, the integer 0 is 0001-01-01T00:00:00 ...

So the format you are looking for is:

2013-09-25T06:00:01

I just pushed a dateTime to NetSuite and it worked.

Johnny Gasyna
  • 461
  • 1
  • 3
  • 13
  • 1
    Looks like this answer is about SuiteTalk. The question is about SuiteScript. – cja Jan 13 '17 at 17:31
1

Import N/format to your script and use one of the date format types:

DATE

DATETIME

DATETIMETZ

var parsedDate = format.parse({
   value: '23/12/2010',
   type: format.Type.DATE
});
Skromak
  • 490
  • 6
  • 12
0

The code looks ok Are there any restrictions on the date field such that you can't set a date in the past? Also your serverDt is the same value as the Netsuite help. Did it copy cleanly? What happens if you cut that string and type it directly?

And finally are you sure you have a datetime field and not a date field. If I apply your code to a date field I get the same error.

bknights
  • 14,408
  • 2
  • 18
  • 31
0

Little addition on the existing ans. Error type -

type: "error.SuiteScriptError",
name: "INVALID_FLD_VALUE",
message: "You have entered an Invalid Field Value 2017-07-13T08:21:12.411Z for the following field: custrecord_lastrundate",

The value need to be set as a java script date() object. Even the simple same string of js date will throw error. If you are using moment then below code will work perfectly. Sample for adding next days.

var now = moment();
now.add(1,'days')
fetchRecord.setValue({
   fieldId : 'custrecord_lastrundate' ,
    value : new Date(now),
    ignoreFieldChange : true
});
Arindam
  • 675
  • 8
  • 15
0

This is related and the other 2.0 answers are correct for Date/Time fields. However I was trying to set the incident time on the case record which is just the time field, and you have to do something like this:

let incidentTime = new Date(0, 0, 0, incidentDate.getHours(), incidentDate.getMinutes());

Notice - its still a Date object, but the Y, M, D values have to be zeroed for it to work.

Ahh Netsuite - you couldn't just do that behind the scenes yourself..

Please let me know if someone has a different solution.

Gerard ONeill
  • 3,914
  • 39
  • 25