简体   繁体   English

NetSuite SuiteScript 2.0 基于复选框禁用字段

[英]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.如果这是一个愚蠢的问题,我深表歉意,但我是 NetSuite 的新手,并且注意到他们的文档绝对是荒谬的可怕和令人厌恶的。 All humor and bitterness aside though, I can't find the details that should exists in SuiteAnswers.撇开所有的幽默和苦涩不谈,我在 SuiteAnswers 中找不到应该存在的细节。 I can find the type Field or Record, but it doesn't show me the options available for those types.我可以找到 Field 或 Record 类型,但它没有向我显示这些类型可用的选项。 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.所以我把它放在了训练指定的 fieldChanged 事件上,下面是我所拥有的。

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.事实证明,我从来没有在文档中找到这个,一旦你从 currentRecord.currentRecord 获取字段,你可以通过 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.我花了很长时间才发现 isDisabled 是字段的属性,然后完全猜测了 isDisabled 是对客户端脚本的 get/set 调用。 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.使用getValue方法和isDisabled来满足此要求。 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.我认为 SuiteScript 2.0 学生指南如果在此过程中包含他们的代码预览会更有帮助。

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).我还包括了之前练习中的一些其他代码(即在优惠券代码中输入“x”时显示一条消息)。

 /** * @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, }; });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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