Merged PR 79: BUG511 保存成功時イベントの際の、非同期処理を同期させ、値を挿入させる改修
BUG511 保存成功時イベントの際の、非同期処理を同期させ、値を挿入させる改修
This commit is contained in:
@@ -488,16 +488,17 @@ export class InsertValueAction implements IAction{
|
|||||||
inputVariablesName = fieldValue;
|
inputVariablesName = fieldValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
//入力された変数名が、contextに不存在の場合、エラーを表示する
|
let inputVariablesExist;
|
||||||
|
//入力された変数名が、contextの変数に存在する場合、inputVariablesExistにtrueに代入する
|
||||||
for(let i=0;i< contextHasVariablesNames.length;i++){
|
for(let i=0;i< contextHasVariablesNames.length;i++){
|
||||||
let inputVariablesExist;
|
|
||||||
if(inputVariablesName === contextHasVariablesNames[i]){
|
if(inputVariablesName === contextHasVariablesNames[i]){
|
||||||
inputVariablesExist = true;
|
inputVariablesExist = true;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!inputVariablesExist){
|
//入力された変数名が、contextの変数に存在しない場合、エラーを表示する
|
||||||
throw new Error("「"+fieldCode+"」"+"フィールドに挿入しようとした変数は、存在しないため、処理を中断しました。");
|
if(!inputVariablesExist){
|
||||||
}
|
throw new Error("「"+fieldCode+"」"+"フィールドに挿入しようとした変数は、存在しないため、処理を中断しました。");
|
||||||
}
|
}
|
||||||
|
|
||||||
if(inputVariablesName){
|
if(inputVariablesName){
|
||||||
@@ -658,24 +659,10 @@ export class InsertValueAction implements IAction{
|
|||||||
}
|
}
|
||||||
|
|
||||||
}else{
|
}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かつ挿入する値が変換できた場合、フィールド(ラジオボタン・ドロップダウン・チェックボックス・複数選択・文字列一行・文字列複数行・リッチエディタ・数値・日付・日時・時刻)にセット
|
//挿入する値を挿入先フィールドに値をセットし、kintoneAPIによってレコード更新を行う
|
||||||
if(conditionResult){
|
async function setUpdateData(conditionResult:boolean,fieldCode:string,event:any,correctFormattedValue :any,correctValues :any) {
|
||||||
|
|
||||||
//値を正しい形式に変換できた場合、フィールドに値をセットする
|
//値を正しい形式に変換できた場合、フィールドに値をセットする
|
||||||
if(correctFormattedValue !== undefined){
|
if(correctFormattedValue !== undefined){
|
||||||
event.record[fieldCode].value = correctFormattedValue;
|
event.record[fieldCode].value = correctFormattedValue;
|
||||||
@@ -683,15 +670,36 @@ export class InsertValueAction implements IAction{
|
|||||||
}else{
|
}else{
|
||||||
event.record[fieldCode].value = correctValues;
|
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 による非同期処理(レコード更新)
|
//kintone async/await による非同期処理(レコード更新)
|
||||||
if(correctFormattedValue !== undefined){
|
async function updateData(fieldCode:string,event:any,insertValue:any) {
|
||||||
await updateRecord(fieldCode,event,correctFormattedValue);
|
try{
|
||||||
//値を正しい形式(配列)に変換できた場合、フィールドに値(配列)をセットする
|
var updatedRecord = {
|
||||||
}else{
|
app: event.appId,
|
||||||
await updateRecord(fieldCode,event,correctValues);
|
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= {
|
result= {
|
||||||
|
|||||||
Reference in New Issue
Block a user