Managing employee information effectively is a crucial task for HR and administrators in any organization. One key aspect of this is understanding employee statuses, which indicate an employee's relationship with the company at a given time.
In NetSuite, administrators often need to retrieve and analyze specific employee statuses to ensure smooth operations and accurate data reporting. A SuiteScript-based saved search is a powerful tool for accomplishing this task. Below, we demonstrate how to use SuiteScript to fetch and log different employee statuses, along with their associated internal IDs.
SuiteScript Code Example
The following code snippet shows how to create and execute a saved search for employee statuses:
require(['N/search'],function(search){
var soSearch = search.create({
type: search.Type.EMPLOYEE_STATUS,
columns:[{
name:'name'
},
{
name:'internalid'
}],
title: 'Different Status of Employee'
})
var resultSet=soSearch.run()
resultSet.each(function(result){
console.log('-----------')
console.log('Status Name: ' + result.getValue({name:'name'}))
console.log('Internal ID: ' + result.getText({name:'internalid'}))
console.log('-----------')
return true
})
})
Key Steps in the Script
1. Require the N/search Module
The script starts by importing the N/search module, which provides the API for creating and running saved searches in SuiteScript.
2. Define the Saved Search
A search is created with the search.create method, targeting the EMPLOYEE_STATUS type. The search specifies two columns:
- name: The status name.
- internalid: The internal ID associated with each employee status.
3. Execute the Search and Process Results
The run method executes the search and returns a resultSet object containing the results. Each result is processed using the each method, which logs the status name and internal ID to the console.
Expected Output
Running this script will output each employee status along with its internal ID in the following format:
The sample code described herein is provided on an "as is" basis, without warranty of any kind, to the fullest extent permitted by law. Oracle + NetSuite Inc. does not warrant or guarantee the individual success developers may have in implementing the sample code on their development platforms or in using their own Web server configurations.
Oracle + NetSuite Inc. does not warrant, guarantee or make any representations regarding the use, results of use, accuracy, timeliness or completeness of any data or information relating to the sample code. Oracle + NetSuite Inc. disclaims all warranties, express or implied, and in particular, disclaims all warranties of merchantability, fitness for a particular purpose, and warranties related to the code, or any service or software related thereto.
Oracle + NetSuite Inc. shall not be liable for any direct, indirect or consequential damages or costs of any type arising out of any action taken by you or others related to the sample code.
To know more about deploying SuiteScript, check these New to NetSuite Articles.
Do you have another way on how to create saved searches in SuiteScript? Feel free to share them here!