Monday, November 26, 2018

Add Days to a Date Field via Workflow

Duration: 8 minutes


Disclaimer: This solution only works on client-side scripts

On a Set Field Value action, use the nlapiAddDays to add number of days. Below is the sample formula or scripts:

nlapiDateToString(nlapiAddDays(new Date(nlapiGetFieldValue('expectedclosedate')),14))

Please note that this only supports the DD MONTH, YYYY and YYYY/MM/DD date format (Configured on Home > Set Preferences). See below for an example workflow:
1. Go to  Customization > Scripting WorkflowsNew
2. Set the following:
   Name: Opportunity Date Conversion
   Record Type: Opportunity
   Execute as Admin is checked
   Release Status: Released
   Event Based: On Create and On Update
   Trigger Type: Before Record Load
2. Create State 1
3. Click on New Action > Set Field Value
4. Set the following:
   Trigger On: After Field Edit
   Client Fields: Expected Close
   Parameters: Date
        Formula: nlapiDateToString(nlapiAddDays(new Date(nlapiGetFieldValue('expectedclosedate')),14))
3. To test, go to Transactions > Sales > Create Opportunities
4. Select 11/8/2011 on Expected Close
Date Created set to 11/22/2011 due to the workflow.
Defect 208569 has been filed since not all date format is supported using the nlapiAddDays.

Disclaimer: The sample code described herein is provided on an"as is" basis, without warranty of any kind, to the fullest extentpermitted by law. NetSuite Inc. does not warrant or guarantee the individualsuccess developers may have in implementing the sample code on theirdevelopment platforms or in using their own Web server configurations.

NetSuite Inc.does not warrant, guarantee or make any representations regarding the use,results of use, accuracy, timeliness or completeness of any data or informationrelating to the sample code. NetSuite Inc. disclaims all warranties, express orimplied, and in particular, disclaims all warranties of merchantability,fitness for a particular purpose, and warranties related to the code, or anyservice or software related thereto.

NetSuite Inc. shall not be liablefor any direct, indirect or consequential damages or costs of any type arisingout of any action taken by you or others related to the sample code.

No comments:

Post a Comment