diff --git a/plugin/kintone-addins/src/actions/insert-value.ts b/plugin/kintone-addins/src/actions/insert-value.ts index e447eb0..14af242 100644 --- a/plugin/kintone-addins/src/actions/insert-value.ts +++ b/plugin/kintone-addins/src/actions/insert-value.ts @@ -488,16 +488,17 @@ export class InsertValueAction implements IAction{ inputVariablesName = fieldValue; } - //入力された変数名が、contextに不存在の場合、エラーを表示する + let inputVariablesExist; + //入力された変数名が、contextの変数に存在する場合、inputVariablesExistにtrueに代入する for(let i=0;i< contextHasVariablesNames.length;i++){ - let inputVariablesExist; if(inputVariablesName === contextHasVariablesNames[i]){ inputVariablesExist = true; } + } - if(!inputVariablesExist){ - throw new Error("「"+fieldCode+"」"+"フィールドに挿入しようとした変数は、存在しないため、処理を中断しました。"); - } + //入力された変数名が、contextの変数に存在しない場合、エラーを表示する + if(!inputVariablesExist){ + throw new Error("「"+fieldCode+"」"+"フィールドに挿入しようとした変数は、存在しないため、処理を中断しました。"); } if(inputVariablesName){ @@ -658,24 +659,10 @@ 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){ + //挿入する値を挿入先フィールドに値をセットし、kintoneAPIによってレコード更新を行う + async function setUpdateData(conditionResult:boolean,fieldCode:string,event:any,correctFormattedValue :any,correctValues :any) { + //値を正しい形式に変換できた場合、フィールドに値をセットする if(correctFormattedValue !== undefined){ event.record[fieldCode].value = correctFormattedValue; @@ -683,15 +670,36 @@ export class InsertValueAction implements IAction{ }else{ event.record[fieldCode].value = correctValues; } + + // 条件が真の場合の処理、kintoneAPIによる非同期処理(レコード更新) + if(conditionResult){ + if(correctFormattedValue !== undefined){ + await updateData(fieldCode,event,correctFormattedValue); + }else{ + await updateData(fieldCode,event,correctValues); + } + } } //kintone async/await による非同期処理(レコード更新) - if(correctFormattedValue !== undefined){ - await updateRecord(fieldCode,event,correctFormattedValue); - //値を正しい形式(配列)に変換できた場合、フィールドに値(配列)をセットする - }else{ - await updateRecord(fieldCode,event,correctValues); + async function updateData(fieldCode:string,event:any,insertValue:any) { + try{ + var updatedRecord = { + app: event.appId, + id: event.recordId, + record: {[fieldCode]:{"value":insertValue}} + }; + //APIでユーザー情報を取得する + const resp =await kintone.api(kintone.api.url('/k/v1/record', true), 'PUT', updatedRecord) + + }catch{ + return false; + } } + + // 関数の呼び出し + setUpdateData(conditionResult,fieldCode,event,correctFormattedValue,correctValues); + }; result= {