javascriptnetsuitesuitescriptclientscript

How to use nlapiAddMonths to set a field value 2 month after a trandate? (in client script)


i m trying to populate a custom field with the value of the corresponding trandate(2 months ahead) e.g if the trandate is 13/05/2019 then the custom field should be 13/07/2019. I am using nlapiAddMoths() in my client script(field changed function) but receiving error. Can anyone help me with this?

function fieldchanged(type,name)//in netsuite, function will be field changed
{
    if (name=='trandate')
    {
        var newdate = nlapiAddMonths(trandate, 2)
        nlapiSetFieldValue('custbody_eta_date_test',newdate,true);//custbody_eta_date_test is my custom field where i want the incremented date to be populated
    }
}

Solution

  • For one thing you are using the field name instead of the field value. Try:

    var newdate = nlapiAddMonths(nlapiStringToDate(nlapiGetFieldValue('trandate')), 2)