Files
KintoneAppBuilder/plugin/kintone-addins/src/actions/counter-check.ts
Shohtetsu Ma 24fca834e0 Merged PR 70: BUG527:エラーの共通処理追加
各の内容を対応しました。
1.エラーの共通処理追加
2.各アクションのtry..catch中のエラー関連処理の対応
3.BUG527,521,522,514,504修正

Related work items: #504, #514, #521, #522, #525, #527
2024-07-31 09:50:18 +00:00

77 lines
2.3 KiB
TypeScript

import { actionAddins } from ".";
import { IAction,IActionResult, IActionNode, IActionProperty, IField, IContext} from "../types/ActionTypes";
/**
* アクションの属性定義
*/
interface IStrCountCheckProps{
field:IField;//チェックするフィールドの対象
message:string;//エラーメッセージ
maxLength:number;//
}
/**
* 正規表現チェックアクション
*/
export class StrCountCheckAciton implements IAction{
name: string;
actionProps: IActionProperty[];
props:IStrCountCheckProps;
constructor(){
this.name="文字数チェック";
this.actionProps=[];
this.props={
field:{code:''},
message:'',
maxLength:0
}
//アクションを登録する
this.register();
}
/**
* アクションの実行を呼び出す
* @param actionNode
* @param event
* @returns
*/
async process(actionNode:IActionNode,event:any,context:IContext):Promise<IActionResult> {
let result={
canNext:true,
result:false
};
try{
//属性設定を取得する
this.actionProps=actionNode.actionProps;
if (!('field' in actionNode.ActionValue) && !('message' in actionNode.ActionValue) && !('strExpression'in actionNode.ActionValue)) {
return result
}
this.props = actionNode.ActionValue as IStrCountCheckProps;
//条件式の計算結果を取得
const record = event.record;
const value = record[this.props.field.code].value;
const maxLength = this.props.maxLength;
if(value === undefined || value === '' ){
return result;
}else if(maxLength < value.length){
record[this.props.field.code].error = this.props.message;
}else{
record[this.props.field.code].error = null;
}
result= {
canNext:true,
result:true
}
return result;
}catch(error){
context.errors.handleError(error,actionNode);
result.canNext=false;
return result;
}
};
register(): void {
actionAddins[this.name]=this;
}
}
new StrCountCheckAciton();