admin管理员组

文章数量:1022712

I am new to netsuite scripting using javascript. I like to ask, how can I set field mandatory to false using javascript.

Hope that someone can help me.

I am new to netsuite scripting using javascript. I like to ask, how can I set field mandatory to false using javascript.

Hope that someone can help me.

Share Improve this question edited Apr 6, 2015 at 8:02 Code Lღver 15.6k16 gold badges59 silver badges75 bronze badges asked Apr 6, 2015 at 7:01 user3627301user3627301 313 silver badges12 bronze badges 3
  • I try to use the API setMandatory(mandatory) but it doesnt work or i dont know how to use it. Appreciate the help. Thank you – user3627301 Commented Apr 6, 2015 at 7:04
  • Please show some code. – phts Commented Apr 6, 2015 at 8:09
  • var field = nlapiGetField('fieldname'); field.setMandatory(false); – user3627301 Commented Apr 6, 2015 at 8:13
Add a ment  | 

6 Answers 6

Reset to default 2

Note :

If you use nlapiGetField(fieldname) in a client script to return a nlobjField object, the object returned is read-only. This means that you can use nlobjField getter methods on the object, however, you cannot use nlobjField setter methods to set field properties.

However you can use nlapiSubmitRecord(item_obj, true, true); to ignore mandatory fields on a record. For more details check out the included parameters in the method.
nlapiSubmitRecord(record, doSourcing, ignoreMandatoryFields);

You are using the correct methods, but setMandatory is not supported in a client script. You can instead try using the exact same code in a User Event, Before Load event handler.

Contrary to the documentation, the nlobjField returned by nlapiGetField is not read-only. Some of the setter methods still work (e.g. setDisplayType) on the client side. You can experiment with which ones do and do not work, but setMandatory is confirmed as not supported on the client side.

Using SS2.0 on a client script you can make it mandatory with this code:

var newSupervisorField = context.currentRecord.getField('custrecord_new_supervisor');
newSupervisorField.isMandatory = true;

This is what worked for me based on the input from @erictgrubaugh and @user3627301

function fieldChanged(type,name){   
    var metodPayment=nlapiGetFieldText('field_id_to_check');
    if ((name == 'field_id_to_monitor_for_change') && (metodPayment=='Financing')) {            
        var field1 = nlapiGetField('field_id_to_be_disabled'); 
        field1.setDisplayType('disabled');
    }               
}

You can set mandatory using SuiteScript 2.0 though although it does not works in 1.0.

Below, is an example snippet using client script on customer record

var currentRecord;require(['N/currentRecord'], (currentRecord) => {
  var field = currentRecord.get().getField('ments');
  field.isMandatory = true;
})

Maybe my answer was already late but for others that came across this post, this is how I do it via client script.

nlapiSetFieldMandatory('yourFieldId', true);

This was already tested because I am using this often. Though some says you cannot set fields to mandatory via client but you can. I did not find any docs about this on netsuite docs though.

I am new to netsuite scripting using javascript. I like to ask, how can I set field mandatory to false using javascript.

Hope that someone can help me.

I am new to netsuite scripting using javascript. I like to ask, how can I set field mandatory to false using javascript.

Hope that someone can help me.

Share Improve this question edited Apr 6, 2015 at 8:02 Code Lღver 15.6k16 gold badges59 silver badges75 bronze badges asked Apr 6, 2015 at 7:01 user3627301user3627301 313 silver badges12 bronze badges 3
  • I try to use the API setMandatory(mandatory) but it doesnt work or i dont know how to use it. Appreciate the help. Thank you – user3627301 Commented Apr 6, 2015 at 7:04
  • Please show some code. – phts Commented Apr 6, 2015 at 8:09
  • var field = nlapiGetField('fieldname'); field.setMandatory(false); – user3627301 Commented Apr 6, 2015 at 8:13
Add a ment  | 

6 Answers 6

Reset to default 2

Note :

If you use nlapiGetField(fieldname) in a client script to return a nlobjField object, the object returned is read-only. This means that you can use nlobjField getter methods on the object, however, you cannot use nlobjField setter methods to set field properties.

However you can use nlapiSubmitRecord(item_obj, true, true); to ignore mandatory fields on a record. For more details check out the included parameters in the method.
nlapiSubmitRecord(record, doSourcing, ignoreMandatoryFields);

You are using the correct methods, but setMandatory is not supported in a client script. You can instead try using the exact same code in a User Event, Before Load event handler.

Contrary to the documentation, the nlobjField returned by nlapiGetField is not read-only. Some of the setter methods still work (e.g. setDisplayType) on the client side. You can experiment with which ones do and do not work, but setMandatory is confirmed as not supported on the client side.

Using SS2.0 on a client script you can make it mandatory with this code:

var newSupervisorField = context.currentRecord.getField('custrecord_new_supervisor');
newSupervisorField.isMandatory = true;

This is what worked for me based on the input from @erictgrubaugh and @user3627301

function fieldChanged(type,name){   
    var metodPayment=nlapiGetFieldText('field_id_to_check');
    if ((name == 'field_id_to_monitor_for_change') && (metodPayment=='Financing')) {            
        var field1 = nlapiGetField('field_id_to_be_disabled'); 
        field1.setDisplayType('disabled');
    }               
}

You can set mandatory using SuiteScript 2.0 though although it does not works in 1.0.

Below, is an example snippet using client script on customer record

var currentRecord;require(['N/currentRecord'], (currentRecord) => {
  var field = currentRecord.get().getField('ments');
  field.isMandatory = true;
})

Maybe my answer was already late but for others that came across this post, this is how I do it via client script.

nlapiSetFieldMandatory('yourFieldId', true);

This was already tested because I am using this often. Though some says you cannot set fields to mandatory via client but you can. I did not find any docs about this on netsuite docs though.

本文标签: netsuiteHow can i set field mandatory to false using javascriptStack Overflow