簡體   English   中英

NetSuite SuiteScript 2.0 基於復選框禁用字段

[英]NetSuite SuiteScript 2.0 disable field based on checkbox

如果這是一個愚蠢的問題,我深表歉意,但我是 NetSuite 的新手,並且注意到他們的文檔絕對是荒謬的可怕和令人厭惡的。 撇開所有的幽默和苦澀不談,我在 SuiteAnswers 中找不到應該存在的細節。 我可以找到 Field 或 Record 類型,但它沒有向我顯示這些類型可用的選項。 它只顯示調用哪些方法來返回字段或記錄。

所以我把它放在了訓練指定的 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;
        }
    }

事實證明,我從來沒有在文檔中找到這個,一旦你從 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, "");
        }
    }
}

我希望這將有所幫助。

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

這是一個很好的問題,這是您正在尋找的最簡單的解決方案。 使用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;
  }
}



 

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

完全同意。 我認為 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, }; });

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM