Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
411 views
in Technique[技术] by (71.8m points)

javascript - SuiteScript 2.0 Dialog Button Return "true" isn't working

I'm trying to deploy a script that will validade if a field value is true or false (checkbox). Case the field value = false, than I would like to raise a dialog with "Ok" and "cancel" button, and when the user press "Ok" it will save it anyway. In case of press "cancel" it will return to the form.

But when the field = false and the user press "Ok" the record isn't saved. BTW: When the field = true, it works fine.

This is my code:

/**
 * @NApiVersion 2.x
 * @NScriptType ClientScript
 * @NModuleScope SameAccount
 */
define(["N/currentRecord", "N/runtime", "N/ui/dialog"], /**
 * @param {currentRecord} currentRecord
 * @param {runtime} runtime
 * @param {dialog} dialog
 */ function (currentRecord, runtime, dialog) {
  /**
   * Function to be executed after page is initialized.
   *
   * @param {Object} scriptContext
   * @param {Record} scriptContext.currentRecord - Current form record
   * @param {string} scriptContext.mode - The mode in which the record is being accessed (create, copy, or edit)
   *
   * @since 2015.2
   */
  function pageInit(scriptContext) {
    var userObj = runtime.getCurrentUser();
    var userRole = userObj.role;
    var currentRecord = scriptContext.currentRecord;
    var itmCheck = currentRecord.getField({
      fieldId: "custitem_ek_itm_fisc_check",
    });
    var expAccount = currentRecord.getField({
      fieldId: "expenseaccount",
    });

    var excAccount = currentRecord.getField({
      fieldId: "billexchratevarianceacct",
    });

    var priceVariance = currentRecord.getField({
      fieldId: "billpricevarianceacct",
    });

    var qntVariance = currentRecord.getField({
      fieldId: "billqtyvarianceacct",
    });

    if (
      userRole !== 3 &&
      userRole !== 1030 &&
      userRole !== 1043 &&
      userRole !== 1047
    ) {
      itmCheck.isDisabled = true;
      expAccount.isDisabled = true;
      excAccount.isDisabled = true;
      priceVariance.isDisabled = true;
      qntVariance.isDisabled = true;
    }
  }

  /**
   * Validation function to be executed when record is saved.
   *
   * @param {Object} scriptContext
   * @param {Record} scriptContext.currentRecord - Current form record
   * @returns {boolean} Return true if record is valid
   *
   * @since 2015.2
   */
  function saveRecord(scriptContext) {
    try {
      var options = {
        title: "Check de Item n?o preenchido",
        message:
          'O campo "Item Verificado pelo Fiscal?" n?o foi preenchido. Deseja proseguir?',
      };
      var userObj = runtime.getCurrentUser();
      var userRole = userObj.role;
      var currentRecord = scriptContext.currentRecord;
      var itmCheckValue = currentRecord.getValue({
        fieldId: "custitem_ek_itm_fisc_check",
      });

      if (
        userRole == 3 ||
        userRole == 1030 ||
        userRole == 1043 ||
        userRole == 1047
      ) {
        function sucess(result) {
          if (result == true) {
            console.log(result, itmCheckValue);
            return true;
          }
        }
        function failure(reason) {
          console.log(reason, itmCheckValue);

          return false;
        }
        if (itmCheckValue == false) {
          dialog.confirm(options).then(sucess).catch(failure);
        } else {
          return true;
        }
      }
    } catch (err) {
      log.error(err);
    }
  }

  return {
    pageInit: pageInit,
    saveRecord: saveRecord,
  };
});

Thanks in advance!

question from:https://stackoverflow.com/questions/65833248/suitescript-2-0-dialog-button-return-true-isnt-working

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Oracle response :

"There is an enhancement for this.

Enhancement 408502: SuiteScript 2.0 > N/ui/dialog Module > Add non-promise API | No equivalent non-promise API"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...