kai
(kai)
1
お世話になっております。
if文の条件が正しく動かない場合があり、ご存知の方はご教授よろしくお願いいたします。
record[“フィールドコード”].value;で取得し変数に格納済み
【項目の詳細】
・DiagnosisResult:ドロップダウン項目
・CP_CorrectivePlanExistense:ドロップダウン項目
・CorrectiveEndDate:日付項目
上記の日付項目が未入力の場合、「undefined」で帰ってくるので条件に使用していますが日付項目が入力済みの場合で値が入っている状態でもundefinedのif文を通過してしまう場合がありますが原因がわかりません
if (DiagnosisResult == '脆弱性なし' && CP_CorrectivePlanExistense == undefined && !(CorrectiveEndDate == undefined)) {
// if (DiagnosisResult == conditionsLabel3 && CP_CorrectivePlanExistense == undefined && CorrectiveEndDate != undefined) {
event.record.CorrectiveEndDate.error = '「日付」' + errorLabel1; //是正終了予定日
event.error = '是正計画グループ内にある「是正終了予定日」' + errorLabel1;
console.log('P9_No5');
}
pomo
2
if文で== を3つ使用してますが、===(厳密等価演算子)に置き換えてみてはいかがでしょうか?
pomo
4
イベント発生タイミングが不明ですので保存のタイミングと仮定して、
(() => {
kintone.events.on([
`app.record.create.submit`,
`app.record.edit.submit`,
],
function (event) {
const field1 = "DiagnosisResultのフィールドコード"
const field2 = "CP_CorrectivePlanExistenseのフィールドコード"
const field3 = "CorrectiveEndDateのフィールドコード"
const record = event.record
const DiagnosisResult = record[field1].value
const CP_CorrectivePlanExistense = record[field2].value
const CorrectiveEndDate = record[field3].value
const errorLabel1 = "エラーです"
// 脆弱性なし、かつCP_CorrectivePlanExistenseとCorrectiveEndDateがundefinedのとき
if (DiagnosisResult === '脆弱性なし' && !CP_CorrectivePlanExistense && !CorrectiveEndDate) {
event.record[field2].error = '「日付」' + errorLabel1; //是正終了予定日
event.error = '是正計画グループ内にある「是正終了予定日」' + errorLabel1;
console.log('P9_No5');
}
return event;
});
})()
上記でif文は全ての条件が達成したときにerrorに入りますが、この辺りの望んでいる条件があまり理解できてないので、
もし、日付がundefiendの場合だけでもerrorに入れたい場合は前二つ両方をくくって、1つ目の条件か2つ目の条件どちらかがtrueの場合としてerrorに入ってあげる等条件を適切に変更してください。
if ((DiagnosisResult === '脆弱性なし' && !CP_CorrectivePlanExistense) || !CorrectiveEndDate){
~~~~
}
kai
(kai)
5
pomo様
上記のソースを参考に試したところうまく動きました。
ありがとうございました。
「いいね!」 1