之前写了一篇工作流的Demo文章 - Oracle Workflow Demo (1) - 一个简单的请假申请工作流 ,这篇文章在那个工作流的基础上增加一些功能。
增加一个Function来自动的判断Employee的Manager谁,然后把工作流走到那个对应的Manager上
新增一个Function,属性中指定一个Procedure,这里可以先指定procedure,再来定义procedure
然后在流程图中,新增一个Function图标,并关联上边新创建的Function,如果Result Type为True则继续流程,如果为False,则终止。
接下定义PTLEAVE Package,这个Package用于查找Employee的上级经理是谁,注意Procedure的格式是严格规定的,包括次序
CREATE OR REPLACE PACKAGE PTLEAVE AS
Procedure find_approver(itemtype in varchar2,
itemkey in varchar2,
actid in number,
funcmode in varchar2,
resultout out varchar2);
END PTLEAVE;
/
CREATE OR REPLACE PACKAGE BODY PTLEAVE AS
--Find Who is the manager of Employee
--Input/Output Parameter must follow below format
Procedure find_approver(itemtype in varchar2,
itemkey in varchar2,
actid in number,
funcmode in varchar2,
resultout out varchar2) AS
v_manager varchar2(30);
v_employee varchar2(30);
BEGIN
If funcmode in ('RUN','RETRY') THEN
--Get Employee attribute value
v_employee:=wf_engine.getItemAttrText(itemtype ,itemkey,'EMPLOYEE');
--Find Who is Manager
select m.user_name
into v_manager
from fnd_user u, per_all_assignments_f a, fnd_user m
where u.user_name=v_employee
and u.employee_id=a.person_id
and m.employee_id=a.supervisor_id
and a.effective_end_date>sysdate
;
if v_manager is null then
resultout:='COMPLETE:F';
ELSE
----Assign Manager to MANAGER attribute
wf_engine.SetItemAttrText(itemtype ,itemkey,'MANAGER',v_manager);
resultout:='COMPLETE:T';
end if;
end if;
exception
when others then
resultout:='ERROR:'||sqlcode;
END find_approver;
END PTLEAVE;
/
Test:
运行Workflow,只输入Employee的名字,不输入Manager,工作流程就会自动找到对应的经理来处理这条工作流。
Workflow Demo File: TPLEAVE_Sample2.wft