Monday, April 15, 2019

Add a Day to Expected Ship Date(custom) on a Sales Order after a Specific Time of the Day has Passed

A Scheduled Script to Add a day to Expected Ship Date(custom) on an SO after a specific time of the day has passed

1. Create a Transaction Body Field

Navigate to Customization > Lists, Records, & Fields > Transaction Body Field > New

  • Label: Expected Ship Date
  • ID: custbodyexpectedshipdate
  • Type: Date
  • Store Value: true
  • Applies To tab > Sale : checked
  • Display tab > Subtab: Main
  • Save
2. Create a saved search in UI that gets a list of sales orders that are not closed/fulfilled and have the Expected Ship Date as the current date.

Navigate to Lists > Search > Saved Searches > New >Select Transactions

  • Search Title : Sales Orders Search
  • Criteria :

         -Type:Sales Order
         -Status: any of Sales Order:Pending Approval, Sales Order: Partially Fulfilled ,   Sales Order: Pending Fulfillment
         -Expected Ship Date : is on Today

3. Create a scheduled script file 'scheduledscript.js' with following code 

function setDate()
var SearchResults = new Array(); //initialize a new array to store search results
  SearchResults = nlapiSearchRecord(null, 'customsearch35'); // call the search 'customsearch35' created in step 2
  var i=0;
  for (i=0; i< SearchResults.length ; i++) // loop through the search results
  var recordId = SearchResults[i].getId(); //get the current record's internal id
  var record=nlapiLoadRecord('salesorder',recordId); // load the current record
  var datetime= record.getFieldValue('custbodyexpectedshipdate');  //get the value of custom date field created in step 1
  var dateObj= nlapiStringToDate(datetime); // convert the string 'datetime' to date object

  var addDateObj=nlapiAddDays(dateObj,1);  // add a day to the date object
  var addDateObjString= nlapiDateToString(addDateObj); // convert the date object to string 
  record.setFieldValue('custbodyexpectedshipdate', addDateObjString); // assign the converted date to the custom date field
  nlapiSubmitRecord(record); // save the record

4. Create a scheduled Script record in NetSuite. Customization > Scripting > Scripts New >Select Scheduled Script 

  • Scripts tab
        Script File: scheduledscript.js
        Function: setDate

  • Save & Deploy

5. Script Deployment Record:

  • Schedule tab :

    Select the schedule

Note:  Suppose you specify the script to execute everyday at 12:00 pm, the script will execute and will add a day to the Expected Ship Date.

DISCLAIMER: The sample solution describedherein is provided on an "as is" basis, without warranty of any kind,to the fullest extent permitted by law. Netsuite Inc. does not warrant orguarantee the individual success developers may have in implementing the samplecode on their development platforms or in using their own Web serverconfigurations.

Netsuite Inc. does notwarrant, guarantee or make any representations regarding the use, results ofuse, accuracy, timeliness or completeness of any data or information relatingto the sample code. Netsuite Inc. disclaims all warranties, express or implied,and in particular, disclaims all warranties of merchantability, fitness for aparticular purpose, and warranties related to the code, or any service orsoftware related thereto.

Netsuite Inc. shallnot be liable for any direct, indirect or consequential damages or costs of anytype arising out of any action taken by you or others related to the samplecode.

No comments:

Post a Comment