Merged PR 52: fix: 値挿入のコンポーネント BUG523 [値挿入]日時に挿入できない BUG517 [値挿入]対象イベント編集成功後に挿入されない の修正

fix: 値挿入のコンポーネント BUG523 [値挿入]日時に挿入できない BUG517 [値挿入]対象イベント編集成功後に挿入されない の修正

BUG523 「2024-07-05T01:32:25.552Z」(ミリ秒を含めた)日時形式と「2024-07-28T17:00:00Z」(ミリ秒を含めない)日時形式も日時フィールドに値挿入できるよう、修正いたしました。

BUG517 保存成功時イベントに値が挿入されないため、保存成功時イベントはasync/await による非同期処理でフィールドに値を挿入、レコードを更新するよう修正いたしました。

Related work items: #517, #523
This commit is contained in:
Yukina Mori
2024-07-18 06:21:19 +00:00
committed by Takuto Yoshida(タクト)

View File

@@ -88,7 +88,8 @@ export class InsertValueAction implements IAction{
let singleDigitMonthDay = inputValue.match(/(\d{4})-(\d{1})-(\d{1})$/);//4桁の数字-1桁の数字-2桁の数字
let singleDigitMonth = inputValue.match(/(\d{4})-(\d{1})-(\d{2})$/);//4桁の数字-1桁の数字-2桁の数字
let singleDigitDay = inputValue.match(/(\d{4})-(\d{2})-(\d{1})$/);//4桁の数字-2桁の数字-1桁の数字
let dateTime = inputValue.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).000Z/);//時刻入りのUTCの日付形式
let dateTimeMilliSecond = inputValue.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}).(\d{2,3})Z$/);//時刻入りのUTCの日付形式(ミリ秒)
let dateTime = inputValue.match(/(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2})Z$/);//時刻入りのUTCの日付形式
let date;
//date型に変換
date = new Date(inputValue);
@@ -96,7 +97,7 @@ export class InsertValueAction implements IAction{
//date型変換できたか確認
if(date !== undefined && !isNaN(date.getDate())){
//正規表現チェック確認
if(twoDigitMonthDay === null && singleDigitMonth === null && singleDigitDay === null && singleDigitMonthDay === null && dateTime === null){
if(twoDigitMonthDay === null && singleDigitMonth === null && singleDigitDay === null && singleDigitMonthDay === null && dateTime === null && dateTimeMilliSecond === null){
event.record[fieldCode]['error'] = "「"+fieldCode+"」"+"フィールドに入れようとした値は、無効な日付形式です。"; //レコードにエラーを表示
throw new Error("「"+fieldCode+"」"+"フィールドに入れようとした値は、無効な日付形式です。「値を挿入する」コンポーネントの処理を中断しました。");
}
@@ -440,6 +441,9 @@ export class InsertValueAction implements IAction{
}
}
//保存成功イベントの場合、kintone async/await による非同期処理でフィールドに値を挿入する
if(!event.type.includes('success')){
//条件式の結果がtrueかつ挿入する値が変換できた場合、フィールドラジオボタン・ドロップダウン・チェックボックス・複数選択・文字列一行・文字列複数行・リッチエディタ・数値・日付・日時・時刻にセット
if(conditionResult && (correctFormattedValue || correctValues)){
//条件式の結果がtureかつ、値を正しい形式に変換できた場合、フィールドに値をセットする
@@ -451,6 +455,38 @@ export class InsertValueAction implements IAction{
}
}
}else{
//kintone async/await による非同期処理(保存成功時イベントREST API処理時)
async function updateRecord(fieldCode:string,event:any,insertValue:any) {
return new Promise((resolve, reject) => {
var updatedRecord = {
app: event.appId,
id: event.recordId,
record: {[fieldCode]:{"value":insertValue}}
};
kintone.api(kintone.api.url('/k/v1/record', true), 'PUT', updatedRecord, (resp) => {
resolve(resp);
}, (error) => {
reject(error);
});
});
}
//条件式の結果がtrueかつ挿入する値が変換できた場合、フィールドラジオボタン・ドロップダウン・チェックボックス・複数選択・文字列一行・文字列複数行・リッチエディタ・数値・日付・日時・時刻にセット
if(conditionResult && (correctFormattedValue || correctValues)){
//条件式の結果がtureかつ、値を正しい形式に変換できた場合、フィールドに値をセットする
if(correctFormattedValue){
event.record[fieldCode].value = correctFormattedValue;
//条件式の結果がtureかつ、値を正しい形式配列に変換できた場合、フィールドに値配列をセットする
}else if(correctValues.length > 0){
event.record[fieldCode].value = correctValues;
}
}
//kintone async/await による非同期処理(レコード更新)
await updateRecord(fieldCode,event,correctFormattedValue);
};
result= {
canNext:true,
result:true