user3627301
user3627301

Reputation: 31

How can i set field mandatory to false using javascript

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.

Upvotes: 0

Views: 5003

Answers (6)

HTTP
HTTP

Reputation: 1724

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.

Upvotes: -1

prasun
prasun

Reputation: 7343

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('comments');
  field.isMandatory = true;
})

Upvotes: 1

Frewuill
Frewuill

Reputation: 181

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

Upvotes: 1

Skromak
Skromak

Reputation: 560

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;

Upvotes: 1

erictgrubaugh
erictgrubaugh

Reputation: 8847

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.

Upvotes: 1

Rockstar
Rockstar

Reputation: 2288

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

Upvotes: 2

Related Questions