ANS-1006 · SUITESCRIPT DEVELOPMENT

How to Hide Unit Cost and Cost Fields on NetSuite Project Task Assignee Sublist

Since native configuration options are unavailable, a SuiteScript solution is required to manage the visibility and default values of these fields.

Short answer

To hide 'Unit Cost' and 'Cost' fields on the Project Task Assignee sublist, a SuiteScript is necessary. This script handles field visibility in view mode, blanks labels in edit mode, and sets empty unit cost values to zero on submission to prevent errors, as these fields lack native configuration options.

Scenario

NetSuite users often encounter a challenge when attempting to customize the 'Assignee' sublist on Project Task records. Specifically, there are no native configuration options available to hide the 'Unit Cost' or 'Cost' fields. This limitation means that these fields remain visible by default, even when they may not be relevant to a user's workflow or data entry requirements.

Solution

As there are no native configuration options to hide the 'Unit Cost' or 'Cost' fields on the Project Task 'Assignee' sublist, a scripted solution is required. The following example demonstrates a solution implemented using SuiteScript 1.0. It is important to note that SuiteScript 1.0 is a legacy API, and NetSuite's current best practice for new development is SuiteScript 2.0/2.1. The functions and object structures used in this script are specific to SuiteScript 1.0 and would require rewriting for a SuiteScript 2.x implementation.The solution addresses two primary considerations:

  1. Hiding in Edit Mode:

    To effectively hide the column in edit mode while ensuring the value remains persistent, the field label must be blanked out.

  2. Mandatory Field Handling:

    The 'Unit Cost' field is mandatory by default. If a Project Task is saved with an empty 'Unit Cost' (which can occur if the assigned employee has a blank 'Labor Cost'), an unexpected error will occur. To prevent this, the script sets any empty 'Unit Cost' values to 0 during the 'before submit' event.Deploy the following script as a User Event script on the Project Task record.Before Load Function (SuiteScript 1.0):

javascript/** * beforeLoad_hideUnitCost : Before load trigger to be deployed on * Project Task record. * * @param {string} type : the read operation type * @param {nlobjForm} form : an nlobjForm object representing the * current form * @param {nlobjRequest} request : an nlobjRequest object * representing the GET request * * @author frederic.jannelle@erpguru.com */function beforeLoad_hideUnitCost(type, form, request){    if (form != null) {        if ((type == 'create') || (type == 'edit')) {            // Need to make field non-mandatory to allow submission            // of sublist line with an empty unit cost            form.getSubList('assignee').getField('unitcost').setMandatory(false).setLabel('');            form.getSubList('assignee').getField('cost').setMandatory(false).setLabel('');        }        if (type == 'view') {            form.getSubList('assignee').getField('unitcost').setDisplayType('hidden');            form.getSubList('assignee').getField('cost').setDisplayType('hidden');        }    }}

Before Submit Function (SuiteScript 1.0):

javascript/** * beforeSubmit_hideUnitCost : Before submit trigger to be deployed * on Priject Task record. * * @param {string} type : the write operation type * * @author frederic.jannelle@erpguru.com */function beforeSubmit_hideUnitCost(type){    if (type == 'create' || type == 'edit') {        resetEmptyUnitCosts();    }}

Helper Function (SuiteScript 1.0):

javascript/** * resetEmptyUnitCosts : Goes through the list of assignees and for * each line that has an empty unit cost resets it to 0. * * This is done to handle the cases where the Labor Cost is empty * on the employee record and therefore populated as empty on the * assignee line. This will cause an unexpected error on submission * of the project task since the field is considered mandatory. * * @author frederic.jannelle@erpguru.com */function resetEmptyUnitCosts(){    var numberOfLines = nlapiGetLineItemCount('assignee');    for (var i = 1; i < numberOfLines; i++) {        var unitCost = nlapiGetLineItemValue('assignee', 'unitcost', i);        if (unitCost == null || unitCost == '') {            nlapiSetLineItemValue('assignee', 'unitcost', i, 0);        }    }}

Expert NetSuite Support

Need help with this NetSuite issue?

SuiteScript Development consulting and configuration support

Talk to a consultant