申請部門の最終承認者のID、漢字名、役職をフィールド保存したい

custom_SSJSの以下関数にプログラムを記述します。

Apply時、
customExtApplyOnClickAfter関数内に上記を追記
Approve時、
customExtApproveOnClickAfter関数内に上記を追記

try{
		//全部署取得
		var wfDepts = WFAppBean.getWfApp().getWfRoute().getDepartments();
		if(wfDepts){
			wfDept = wfDepts[0];//最初の部署を取得(申請部署)
			if(wfDept){
				var wfSteps = wfDept.getSteps();
				var wfApprovers = null;
				//最終StepのwfApproversをセット
				for(var i=0;i<wfSteps.length;i++){
					wfApprovers = wfSteps[i].getApprovers();
				}
				// 最終承認者のID、漢字名、役職 を取得 (複数の場合はリスト)
				var dept1LastApproverId = "";
				var dept1LastApproverKanji = "";
				var dept1LastApproverTitle = "";
				if(wfApprovers){
					var wfApprover = null;
					var wfAppDetail = null
					for(var j=0;j<wfApprovers.length;j++){
						wfApprover = wfApprovers[j];
						if(wfApprover){
							wfAppDetail = wfApprover.getWfApproverDetail();
							if(wfAppDetail){
								dept1LastApproverId = @Trim(@List(dept1LastApproverId, wfApprover.getUsername(), ""));
								dept1LastApproverKanji = @Trim(@List(dept1LastApproverKanji, wfAppDetail.getKanjiName(), ""));
								dept1LastApproverTitle = @Trim(@List(dept1LastApproverTitle, wfAppDetail.getPostName(), ""));
							}
						}
					}
				}
				//文書に値をセット
				document1.replaceItemValue("Dept1LastApproverId", dept1LastApproverId);//NotesID
				document1.replaceItemValue("Dept1LastApproverKanji", dept1LastApproverKanji);//漢字名
				document1.replaceItemValue("Dept1LastApproverTitle", dept1LastApproverTitle);//役職
			}
		}
	}
	catch(e){
		print("Error in customExtApproveOnClickAfter:"+e)
	}