Thursday, April 4, 2019

Time Bill Record Exposed on Two Views

The Time Record is exposed in two views:

Track Time : Transactions >  Employees > Track Time
Weekly Time Sheet Transactions >  Employees > Weekly Time Sheet

Both of these views are sourcing from the Time Record (internal Id: timebill). The record itself is exposed to SuiteScript, however, the different views may cause errors from your scripts. 

For example: 
Setting Service Item field to be hidden.

Sample User Event Script on Before Load:

var field = nlapiGetField('item');
field.setDisplayType('hidden')


The script above will hide the Service Item Field when you open Track Time, however, when you open Weekly Time Tracking an Unexpected Error will be displayed, with details:
 
TypeError: Cannot call method "setDisplayType" of null

The reason behind this is that on the Weekly Time Tracking View the Service Item Field is no longer a main body field but a sublist field.

What you can do to limit the script to only run on the Track Time view is to check what view is the Time record being shown.

You can add the line:

var req = request.getParameter('weekly');


Then you can evaluate the variable req using an if-else block

if(req == 'T'){  }
else {  }


Full Sample Script:

function beforeLoad(type, form, request){
var req = request.getParameter('weekly');if(req == 'T'){   //do nothing  }else{     var field = nlapiGetField('item');     field.setDisplayType('hidden');  }}

No comments:

Post a Comment