【问题标题】:NetSuite SuiteScript 2.0 disable field based on checkboxNetSuite SuiteScript 2.0 禁用基于复选框的字段
【发布时间】:2017-05-25 15:00:54
【问题描述】:

如果这是一个愚蠢的问题,我深表歉意,但我是 NetSuite 的新手,并且注意到他们的文档绝对是可笑的,可怕的,令人作呕的。除了所有的幽默和苦涩之外,我找不到 SuiteAnswers 中应该存在的细节。我可以找到字段或记录类型,但它没有显示可用于这些类型的选项。它只是显示要调用哪些方法来返回字段或记录。

所以我在培训指定的 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;
        }
    }

【问题讨论】:

    标签: netsuite suitescript


    【解决方案1】:

    事实证明,我从未在文档中找到这一点,一旦您从 currentRecord.currentRecord 获取字段,您可以通过 field.isDisabled 将其设置为禁用。花了我很长时间才发现 isDisabled 是字段的属性,然后完全猜测到 isDisabled 是客户端脚本的 get/set 调用。下面是最终工作的代码。

    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, "");
            }
        }
    }
    

    【讨论】:

    • 你是如何在复选框上附加事件的?
    • 这是一个脚本 2.0,所以 NetSuite 已经处理了。我刚刚检查了是否选中的字段是复选框
    【解决方案2】:

    我希望这会有所帮助。

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

    【讨论】:

      【解决方案3】:

      这是一个好问题,这是您正在寻找的最简单的解决方案。使用getValue 方法和isDisabled 来满足这个要求。该代码是不言自明的。祝你好运。

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

      【讨论】:

        【解决方案4】:

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

        【讨论】:

        • 考虑在代码中添加一些注释以帮助其他用户更好地理解它
        【解决方案5】:

        完全同意。我认为 SuiteScript 2.0 学生指南如果包含他们的代码预览,可能会更有帮助。

        对于仍在关注的其他人,下面的代码对我有用。感谢在这篇文章中做出贡献的其他所有人。也使用您的代码来创建它。我还包括了之前练习中的一些其他代码(即在优惠券代码中输入“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,
        
            };
           });

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2018-07-15
          • 2017-09-19
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多