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:
