Filter search data based on the logged in employee record field value

The requirement is to filter the data returned from a saved search based on the custom field inside the employee record of the currently logged-in NetSuite user(employee).

For this, the logged-in user ID must be fetched using the N/runtime module. I am passing the user internal ID as a global variable ‘userID’. Sample code for filtering:

function getSearchResult() {

    let searchData = common.runSearch({

      type: // type

      filters: [

        // filters

      ],

      columns: [

        // Columns

      ],

    });

 

    // Filter data if approver roles field has data

    let approverRoles = search.lookupFields({ type: search.Type.EMPLOYEE, id: userID, columns: [‘custentity_req_approver_roles’]})[‘custentity_req_approver_roles’];

    if (approverRoles.length === 0) { // No approver roles provided for the logged in User

      // Filter criteria is a column named restricted(boolean)

      searchData = searchData.filter(fileObj => (fileObj.restricted !== true)); // Remove the files if ‘custrecord_tran_attachment_restrict_est’ checkbox is selected

    }

    return searchData;

  }

Leave a comment

Your email address will not be published. Required fields are marked *