Multiple level of approval using AME
SELECT * FROM (SELECT xx_approval_pkg.approval_insert('REQAPPRV',10,:transactionId) aa FROM DUAL
union all
SELECT xx_approval_pkg.approval_insert('REQAPPRV',20,:transactionId) aa FROM DUAL
union all
SELECT xx_approval_pkg.approval_insert('REQAPPRV',30,:transactionId) aa FROM DUAL
union all
SELECT xx_approval_pkg.approval_insert('REQAPPRV',40,:transactionId) aa FROM DUAL) x WHERE aa <> 'PERSON_ID:0'
Query will call xx_approval_pkg.approval_insert package.function
here, REQAPPRV --means Requisition approval--Can pass any value(EXPENSE,INVOICE,REQAPPRV)
Sequence -10,20,30,40 ---Can send any number of sequences(I tested with upto 100)
:transactionId is the requisition header id for Requosition.
If sequence is 10, program will create hierarchy information and will store in a tem table xxvir.xxvirtu_doc_supervisor and return personid for sequence 10 only. next sequence onwards only return personid (no hierachy creation).
If for any sequence value does not retrun any value that means it will retrun personid=0.
xxvir.xxvirtu_doc_supervisor table values
seq --- person_id---itemtype---itemkey
10----1001-----REQAPPRV---XXX
20---1002---REQAPPRV---XXX
30---1003---REQAPPRV---XXX.
FUNCTION approval_insert (
p_itemtype VARCHAR2,
p_itemkey VARCHAR2,
p_sequence NUMBER,
p_document_id NUMBER
)
RETURN VARCHAR2
AS
v_person_id NUMBER;
--PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
IF p_sequence = 10
THEN
IF p_itemtype = 'EXPENSE'
THEN
exp_approval_list_insert (p_itemtype => 'EXPENSE',
p_itemkey => NULL,
p_document_id => p_document_id
);
ELSIF p_itemtype = 'INVOICE'
THEN
inv_approval_list_insert (p_itemtype => 'INVOICE',
p_itemkey => NULL,
p_document_id => p_document_id
);
ELSIF p_itemtype = 'REQAPPRV'
THEN
req_approval_list_insert (p_itemtype => 'REQAPPRV',
p_itemkey => NULL,
p_document_id => p_document_id
);
END IF;
--RETURN 0;
END IF;
--ELSE
BEGIN
SELECT person_id
INTO v_person_id
FROM xxvir.xxvirtu_doc_supervisor
WHERE itemtype = p_itemtype
AND document_id = p_document_id
AND sequence_number = p_sequence;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
v_person_id := 0;
RETURN ('PERSON_ID:' || v_person_id);
END;
--RETURN v_person_id;
RETURN ('PERSON_ID:' || v_person_id);
-- END IF;
END;
Based on the document type and document id program will generate the hierarchy and will store the person id value in xxvir.xxvirtu_doc_supervisor table.
AME query will return like 1001,1002,1003 (person ids) and then approval message will go to first 1001, once it approves the approval message will go to 1002 and then to1003. Finally if 1003 approves then the requisition will be approved.
- Define attributes as per the requirement
- Define conditions as per the requirement
- Define approver group
Give Name and Description
Select Order Number-1
Select Voting method-Serial
Select Usage Type-Dynamic
SELECT * FROM (SELECT xx_approval_pkg.approval_insert('REQAPPRV',10,:transactionId) aa FROM DUAL
union all
SELECT xx_approval_pkg.approval_insert('REQAPPRV',20,:transactionId) aa FROM DUAL
union all
SELECT xx_approval_pkg.approval_insert('REQAPPRV',30,:transactionId) aa FROM DUAL
union all
SELECT xx_approval_pkg.approval_insert('REQAPPRV',40,:transactionId) aa FROM DUAL) x WHERE aa <> 'PERSON_ID:0'
- Define Action Type
- Define Rule.
Query will call xx_approval_pkg.approval_insert package.function
here, REQAPPRV --means Requisition approval--Can pass any value(EXPENSE,INVOICE,REQAPPRV)
Sequence -10,20,30,40 ---Can send any number of sequences(I tested with upto 100)
:transactionId is the requisition header id for Requosition.
If sequence is 10, program will create hierarchy information and will store in a tem table xxvir.xxvirtu_doc_supervisor and return personid for sequence 10 only. next sequence onwards only return personid (no hierachy creation).
If for any sequence value does not retrun any value that means it will retrun personid=0.
xxvir.xxvirtu_doc_supervisor table values
seq --- person_id---itemtype---itemkey
10----1001-----REQAPPRV---XXX
20---1002---REQAPPRV---XXX
30---1003---REQAPPRV---XXX.
FUNCTION approval_insert (
p_itemtype VARCHAR2,
p_itemkey VARCHAR2,
p_sequence NUMBER,
p_document_id NUMBER
)
RETURN VARCHAR2
AS
v_person_id NUMBER;
--PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
IF p_sequence = 10
THEN
IF p_itemtype = 'EXPENSE'
THEN
exp_approval_list_insert (p_itemtype => 'EXPENSE',
p_itemkey => NULL,
p_document_id => p_document_id
);
ELSIF p_itemtype = 'INVOICE'
THEN
inv_approval_list_insert (p_itemtype => 'INVOICE',
p_itemkey => NULL,
p_document_id => p_document_id
);
ELSIF p_itemtype = 'REQAPPRV'
THEN
req_approval_list_insert (p_itemtype => 'REQAPPRV',
p_itemkey => NULL,
p_document_id => p_document_id
);
END IF;
--RETURN 0;
END IF;
--ELSE
BEGIN
SELECT person_id
INTO v_person_id
FROM xxvir.xxvirtu_doc_supervisor
WHERE itemtype = p_itemtype
AND document_id = p_document_id
AND sequence_number = p_sequence;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
v_person_id := 0;
RETURN ('PERSON_ID:' || v_person_id);
END;
--RETURN v_person_id;
RETURN ('PERSON_ID:' || v_person_id);
-- END IF;
END;
Based on the document type and document id program will generate the hierarchy and will store the person id value in xxvir.xxvirtu_doc_supervisor table.
AME query will return like 1001,1002,1003 (person ids) and then approval message will go to first 1001, once it approves the approval message will go to 1002 and then to1003. Finally if 1003 approves then the requisition will be approved.
I really appreciate information shared above. It’s of great help. If someone want to learn Online (Virtual) instructor lead live training in ORACLE AME, kindly contact us http://www.maxmunus.com/contact
ReplyDeleteMaxMunus Offer World Class Virtual Instructor led training on ORACLE AME We have industry expert trainer. We provide Training Material and Software Support. MaxMunus has successfully conducted 100000+ trainings in India, USA, UK, Australlia, Switzerland, Qatar, Saudi Arabia, Bangladesh, Bahrain and UAE etc.
For Demo Contact us.
Saurabh Srivastava
MaxMunus
E-mail: saurabh@maxmunus.com
Skype id: saurabhmaxmunus
Ph:+91 8553576305 / 080 - 41103383
http://www.maxmunus.com/
Hi Sridevi,
ReplyDeleteThanks for the info. It's a very helpful blog. Can you please suggest - how can I return dynamic value for approvers, if the voting method is first responder wins instead of serial.
e.g. - For Serial the approver value being returned is PERSON:1001.
What shold be the format for first responder wins.