简体   繁体   中英

NetSuite SuiteScript 2.0 disable field based on checkbox

I apologize if this is a dumb question, but I am new to NetSuite, and have noticed that their documentation is absolutely ridiculously horrifyingly and atrociously disgusting. All humor and bitterness aside though, I can't find the details that should exists in SuiteAnswers. I can find the type Field or Record, but it doesn't show me the options available for those types. It just shows what methods to call to return a field or record.

So I have it on the fieldChanged event as the training specifies, and below is what I have.

function fieldChanged(context) {
        debugger;
        var customer = context.currentRecord

        if (context.fieldId == 'custentity_apply_coupon') {
            var field = record.getField("custentity_apply_coupon");
            if (record.getValue("custentity_apply_coupon") == true) {
                reord.getField("custentity_coupon_code").isDisabled = false;

            }
            else{
                reord.getField("custentity_coupon_code").isDisabled = true;
            }
            field.isDisabled = false;
        }
    }

Turns out that, and I never found this in the documentation, that once you get the field from currentRecord.currentRecord, you can set it to disabled via field.isDisabled. Took me forever to find out that isDisabled was a property of field, and then took a complete guess to see that isDisabled was a get/set call for ClientSide Scripts. Below is the code that ended up working.

function fieldChanged(scriptContext) {
    var customer = scriptContext.currentRecord;

    if(scriptContext.fieldId == "custentity_sdr_apply_coupon"){
        debugger;
        var field = customer.getField("custentity_sdr_coupon_code");

        field.isDisabled = !customer.getValue(scriptContext.fieldId);
        if(field.isDisabled){
            customer.setValue(field.id, "");
        }
    }
}

I hope this will help.

function fieldChanged(context) {
            var currentRecord = context.currentRecord;
            var approvalChkBox = currentRecord.getValue({
                fieldId: 'supervisorapproval'
            });
            var memoField = currentRecord.getField("memo");
            if (approvalChkBox)
                memoField.isDisabled = true;
            else
                memoField.isDisabled = false;
        }

Thats a good question, this is the simplest solution you are looking for. use getValue method and isDisabled to meet this requirement. the code is self explanatory. Good Luck.

function fieldChanged(context) {
  var record = context.currentRecord;
  var fieldname = context.fieldId;

  var changedValue = record.getValue(fieldname); //getValue method is the key here
  var couponid = record.getField('custentity_kld_coupon_code');

  if (fieldname == 'custentity_kld_apply_coupon' && changedValue == true) {

    couponid.isDisabled = false; //isDisabled helps you to enable or disable a field
  } else {
    couponid.isDisabled = true;
  }
}



 

 var objRec_Curr = scriptContext.currentRecord; var TransferType = objRec_Curr.getCurrentSublistValue({sublistId:'xxxxxxxxxx', fieldId : 'xxxxxxxxxxxx'}); if(TransferType == 'ABC') eval("nlapiDisableLineItemField('custpage_sublist_out', 'custpage_out_transfer_location', true)"); else eval("nlapiDisableLineItemField('custpage_sublist_out', 'custpage_out_transfer_location', false)");

Totally agree. I think the SuiteScript 2.0 Student Guide could've been more helpful if they included a preview of their codes along the way.

For anyone else who is still following along, this code below worked for me. Thanks for everyone else that contributed in this post. Used your codes to create this too. I also included some other codes from the previous exercises (ie displaying a message when entering 'x' into the coupon code).

 /** * @NScriptType ClientScript * @NApiVersion 2.0 */ define([], function() { function fieldChanged (context) { var customer = context.currentRecord; if(context.fieldId = 'custentity_sdr_apply_coupon') { var check = customer.getValue('custentity_sdr_apply_coupon'); var code = customer.getField('custentity_sdr_coupon_code'); if (check == true){ code.isDisabled = false; } else { code.isDisabled = true; } } } function saveRecord(context) { var customer = context.currentRecord; var empCode = customer.getValue('custentity_sdr_coupon_code') if(empCode == 'x') { alert('Invalid code value. Please try again'); return false; } return true; } return { fieldChanged: fieldChanged, saveRecord: saveRecord, }; });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM