How to make sublist field mandatory?

2.6k views Asked by At

This is my pageInit function

function poTransPageInit(type) {
    //   alert('page init');
    var field= nlapiGetLineItemField('item', 'field');
    field.isMandatory = true;
}

what I do wrong here?

2

There are 2 answers

0
Martha On BEST ANSWER

It is true that the isMandatory method is not available in Client Scripts. As a work around you could get the field's value and check the length.

function validateLine(type){
  if(type == 'sublistInternalID'){ //sublistInternalID = sublist internal id, i.e. 'item'
    //get the sublist field value of mandatory column
    var name = nlapiGetCurrentLineItemValue('line', 'fieldId'); //line = line #, fieldId = internal id of field
    //if value length is greater than 0, then there is a value
    if(name.length > 0){
      return true;
    } else {
      alert('Please enter a value for Name field');
      return false;
    }
  }
}
0
Mike Robbins On

field.isMandatory is SuiteScript 2.0. In SuiteScript 1.0, you would use field.setMandatory(true), but apparently that function is not available in client scripts.

You could try moving this logic to a User Event script.