A Quick Netsuite Scripting Tip

When working on SuiteScript, we have different field types and and form fields in NetSuite but to get values from these we have generic functions


These functions always return values as type string. Even for Date and Numeric type of fields.

So when manipulating values returned one should(have to) convert them to right types to avoid bugs.

For example we may apply parseInt or parseFloat for Numeric data.

var val = nlapiGetFieldValue('fieldId');
if( 3 > parseInt(val))

Beware that ParseInt can return NaN so a more efficient way is to use these type of functions

function getNumber(number){
 return (parseFloat(number) == NaN)?0.0:parseFloat(number);

For date type fields we may use standard Netsuite functions


Netsuite Gurus, Please feel free to comment if you find any problem in the code above.

I am a web developer working @ Gaditek

Tagged with: ,
Posted in Netsuite, Programming & Development
5 comments on “A Quick Netsuite Scripting Tip
  1. Scott Seong says:

    How would you assign a value that is defined as a Date/Time type? For example, if we have a custom entity field named custentity_createdate defined as a date/time, and this field is available in Customers.

    customer.setFieldValue(“custentity_createdate”, “2012-06-06 00:00:00”);
    customer.setFieldValue(“custentity_createdate”, “2012-06-06T00:00:00-06:00”);
    customer.setFieldValue(“custentity_createdate”, “1339002061000”); // in milisecond.

    None seems to be working. Any idea how I can assign a Date/Time value to a custom entity?

  2. dreamxtream says:

    @Scott Seong

    In ScuiteScript just create a normal date object. Assign the correct month/day/year values to it and before assigning it to any convert it using nlapiDateToString
    for eg. customer.setFieldValue(“custentity_createdate”, nlapiDateToString(new Date()));

  3. dreamxtream says:

    I think this should also work
    customer.setFieldValue(“custentity_createdate”, ‘1/1/2012 9:59 pm’);

  4. Scott Seong says:

    Yes, ‘1/1/2012 00:00:00 am’ format worked. Millisecond part is optional. I found that trying to update a field through NetSuite custom form will help identify correct format in many cases. Thanks.

  5. geilt says:

    The date function is especially important. Netsuite allows you to customize the format of your dates per user account. IF you try and concatenate dates or come up with your own method to calculate dates, it runs the risk of breaking or being wrong if the date format is changed for the user / account. This happened to me. I had a script someone wrote that was breaking, turns out half the problem was they didn’t know about nlapiStringToDate and vice versa.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

About me
A geek trying to make world a better place to live.

I work on LAMP Stack, SRE and resilience engineering. I also worked on Python, GAE and Netsuite Customization. Currently working @ Cloudways as Software Architect

Profile Links Linkedin | Github | Stackoverflow
Subscribe to this blog
%d bloggers like this: