如何使子列表字段成为必填项?

How to make sublist field mandatory?

这是我的 pageInit 函数

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

我哪里做错了?

field.isMandatory 是 SuiteScript 2.0。在 SuiteScript 1.0 中,您将使用 field.setMandatory(true),但 apparently that function is not available in client scripts.

您可以尝试将此逻辑移至用户事件脚本。

isMandatory 方法确实在客户端脚本中不可用。作为解决方法,您可以获得字段的值并检查长度。

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;
    }
  }
}