import { actionAddins } from "."; import { IField, IAction,IActionResult, IActionNode, IActionProperty } from "../types/ActionTypes"; import { Formatter } from "../util/format"; //右UI画面propertyのname:型: interface IStringJoinProps{ //保存先フィールド saveField:IField; //結合元フィールド1 joinField1:IField; //結合元フィールド2 joinField2:IField; //区切り文字 delimiter:string; } //IActionインタフェースを実装する新しいクラスActionを作成: export class StringJoinAction implements IAction{ name: string; //importから導入顕示定義 actionProps: IActionProperty[]; //上方のinterface Propsから、props受ける属性を定義: props:IStringJoinProps; //関数定義に必要な類名を構築: constructor(){ //pgAdminDBに登録したアクション名(name/subtitle)一致する必要がある: this.name="文字結合"; this.actionProps=[]; this.register(); //プロパティ属性初期化: this.props={ saveField:{code:''}, joinField1:{code:''}, joinField2:{code:''}, delimiter:'' } //リセット上記登録表: this.register(); } /** * アクションの処理を実装する * @param actionNode アクションノード * @param event Kintoneのイベント * @param context コンテキスト(レコード、変数情報を持っている) * @returns */ //非同期処理ある関数下のある属性: async process(actionNode:IActionNode,event:any):Promise { let result={ //後継処理不可: canNext:false, result:false }; try{ //属性設定を取得する: this.actionProps=actionNode.actionProps; //プロパティ設定のデータ型は必要な情報含めますか?全部不存在時return: if (!('saveField' in actionNode.ActionValue) && !('joinField1' in actionNode.ActionValue) && !('joinField2' in actionNode.ActionValue)) { return result } //既定のプロパティのインタフェースへ変換: this.props = actionNode.ActionValue as IStringJoinProps; const record = event.record; //kintoneフィールドタイプ取得: const joinField1type=this.props.joinField1.type; const joinField2type=this.props.joinField2.type; const saveFieldtype=this.props.saveField.type; ////////////////////////////////////////////////////////////////////////////////////////////////////// // //保存先フィールドは文字列フィールドではない場合、エラー発生: if(!(saveFieldtype==='SINGLE_LINE_TEXT'||saveFieldtype==='MULTI_LINE_TEXT'||saveFieldtype==='RICH_TEXT')){ event.error='[エラーメッセージ]:結合保存先対応不可。結合しません'; if (event.type.includes('success')){ window.alert("[windows alert]:"+event.error); } result = { canNext: false, result: false } return result; } ////////////////////////////////////////////////////////////////////////////////////////// //値取得方法定義: function getValue(value:string,type:string|undefined,fieldCode:string,event:any){ if(event.record[fieldCode]?.value===undefined||event.record[fieldCode]?.value===null){ event.record[fieldCode].value=''; } //作成者、更新者: if(type==='CREATOR'||type==='MODIFIER'){ value = event.record[fieldCode]?.value.name; //日時、作成日時、更新日時: }else if(type==='DATETIME'||type==='CREATED_TIME'||type==='UPDATED_TIME'){ if(event.record[fieldCode]?.value!==undefined && event.record[fieldCode]?.value!==''){ value = Formatter.dateFormat(new Date(event.record[fieldCode]?.value),'yyyy-MM-dd HH:mm'); }else{ value=event.record[fieldCode]?.value; } //ユーザ選択、組織選択、グループ選択、添付ファイル名、作業者、カテゴリー: }else if(type==='USER_SELECT'||type==='ORGANIZATION_SELECT'||type==='GROUP_SELECT'||type==='FILE'||type==='STATUS_ASSIGNEE'){ if(event.record[fieldCode]?.value===undefined || event.record[fieldCode]?.value===''){ value = event.record[fieldCode]?.value; }else{ const mototext=event.record[fieldCode]?.value; let arr=[]; for(let i=0;i { //kintone保存先フィールド存在確認: record[this.props.saveField.code].value=saveValue; if (event.type.includes('index')){ window.alert("文字結合行いました。"+this.props.joinField1.name+":"+joinValue1+","+this.props.joinField2.name+":"+joinValue2+"。一覧画面更新成功後自動リロードしません。必要に応じて手動リロードください。"); }else{ window.alert("文字結合行いました。"+this.props.joinField1.name+":"+joinValue1+","+this.props.joinField2.name+":"+joinValue2+"。"); } //一覧画面更新成功後リロード: // if (event.type.includes('index')){ // event.url = location.href.endsWith('/') || location.href.endsWith('&') ? // location.href.slice(0, -1) : // location.href + (location.href.includes('?') ? '&' : '/'); // } }).catch((error) => { event.error = 'エラーが発生しました。結合しません。システム管理者へお問合せください'; window.alert(event.error+"error message:"+error); return event; }); } ////////////////////////////////////////////////////////////////////////////////////////////////////// result= { canNext:true, result:true } return result; }catch(error){; if (event.type.includes('success')){ window.alert("[windows alert]:処理中異常が発生しました。結合しません。システム担当者へお問合せください。errorメッセージ:"+error) } event.error="[エラーメッセージ]:処理中異常が発生しました。結合しません。システム担当者へお問合せください。errorメッセージ:"+error; return { canNext:false, result:false } } } /////////////////////////////////////////////////////////////////////////////////////////////// register(): void { actionAddins[this.name]=this; } } new StringJoinAction();