Automatically Set Posting Period Field using a date from a Custom Date Field
1. Open a Script Editor and enter the following and save as SetPostingPeriod.js:
function clientFieldChanged(type, name, linenum){
if(name == 'custbody_date_fld'){
var months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var custbody_date_fld = nlapiGetFieldValue('custbody_date_fld');
var date = nlapiStringToDate(custbody_date_fld);
var postingPeriod = months[date.getMonth()] + ' ' + date.getFullYear();
nlapiSetFieldText('postingperiod', postingPeriod);
}
}
2. Create a Custom Transaction Body Field. Customization > Lists, Records, & Fields > Transaction Body Fields > New
-- Set ID to: _date_fld
-- Store Value: checked
-- Type: Date
-- Display > Subtab: Main
3. Upload Script to NetSuite's File Cabinet
4. Create SuiteScript Record. Customization > Scripting > Scripts > New > Client
5. Enter Descriptive Name
-- Scripts > Script File: SetPostingPeriod.js
-- Scripts > Field Changed Function: clientFieldChanged
-- Scripts > Deployments
-- Applies To: Invoice, Deployed: Yes, Status: Released
6. Save SuiteScript Record
No comments:
Post a Comment