0

I have the following script, applied to the Timesheet record, which gets called when a change event occurs for any field on a Timesheet record. This works perfectly on a body field, but it fails on the fields inside the timegrid (a child of the Timesheet, I believe). All I am trying to do is simply show/hide a custom field based on the Customer a user chooses when adding time to a timesheet. I want to capture the event, check the customer, and if true hide another field.

The example below is just a starting point to test the isDisplay function. It hides whatever field fires the event. When testing it by changing the customer in the time grid, it fires, gets the correct id, which is literally 'customer', but then call to getField() returns null. However, getField() works fine if I pass it one of the body fields (like date for example).

EXAMPLE:

    define(['N/currentRecord'], function () {

      function fieldChanged(context) {
        //get reference to whichever field is changing and hide it...
        var f = context.currentRecord.getField({fieldId: context.fieldId});      
        f.isDisplay = false; 
      }

      return {
          fieldChanged: fieldChanged
      }
    }
);

Can anyone point me in the right direction? Is there another way I am supposed to get to the time grid fields? I'm brand new to SuiteScript.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Dec 05 '17 at 20:53

1 Answers1

0

Record.getField(options) returns body fields. To get sublist fields you need Record.getCurrentSublistField(options). You could check the Context.sublistId to determine if the field, which was changed, is a sublist field or not.

Maria Berinde-Tampanariu
  • 1,011
  • 1
  • 12
  • 25