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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…