Search This Blog

Sunday, October 12, 2014

5. Steps to start Process of Workflow



1.

BEGIN
WF_ENGINE.CREATEPROCESS(itemtype => 'TEST',
                        itemkey  =>'1',--UNIQUE
                        process  =>'PROCESS1',
                        user_key => 'A',--WE CAN PASS OUR OWN, OPTIONAL ,
                        owner_role => 'OPERATIONS');
                        END;
                       
2.PROCESS CREATED IN BACKEND..
                       
 SELECT * FROM WF_ITEMS
 WHERE ITEM_TYPE = 'TEST'

3. TO CHECK THE PROCESS IN FRONTEND.
sysadmin>workflow>administrator worflow> status monitor


4. TO START THE PROCESS.

BEGIN
WF_ENGINE.STARTPROCESS(itemtype => 'TEST',
                       itemkey  => '1');
                       end;
                      

SELECT * FROM WF_NOTIFICATIONS
WHERE MESSAGE_TYPE = 'TEST'                       


If we want to do create and start process at once use the below:
BEGIN                       
WF_ENGINE.LaunchProcess(itemtype =>'TEST2', --internal name of wf
                        itemkey  =>'1',     --unique key any
                        process => 'PROC2' , --internal name of process
                        userkey => 'A',      --unique key any
                        owner   => 'EG_AFZAL'); --user
END;      

4. Mode of Functions.

Post notification:

After notification is delivered, the funciton/proc will exceute.

same 5 parameters as function should be used.
result should be ignored.

MOdes of functions:

1. Validate. : Fires at when the user tries to respond it validates.
2. Respond.  : it wil read response from user.
3. Forwrard. : forwarding notification to other user (keep ownership with the sam user)
4. Transfer. : Transfer notification ownership to other user.
5. Question  : <request information> requesting more information regarding the same , user/response.
6. Answer    : Replying to the request.
7. Run       : After Validation>Respond> Run will be fired.
8. Timeout   : when the notification gets timeout after period of time.


Use any Workflow
Attach the procedure created in the notification function field.

--for timeout go to Notification properties> Node> Type = Relative Time, Value = 2 min
 Notification tab> Result Type = 'Approval'
  In the same window beside Message click 'Edit'
  Go to Result tab>
    Display name : Approval
    Description  : Approval
    Lookup Type  : Approval




CREATE TABLE XX_POST_NOTI
(SEQUENCE_NUM NUMBER,
ITEM_TYPE VARCHAR2(240),
ITEM_KEY VARCHAR2(240),
ACTIVITY_ID NUMBER,
FUNC_MODE VARCHAR2(240),
ACTION_DATE DATE)


CREATE OR REPLACE PROCEDURE XX_POST_NOTI_PROC
( ITEM_TYPE IN VARCHAR2,
  ITEM_KEY IN VARCHAR2,
  ACT_ID IN NUMBER, --ACTIVITY ID 
  FUNC_MODE IN VARCHAR2,
  RESULT_OUT OUT VARCHAR2)
AS
BEGIN
INSERT INTO XX_POST_NOTI
VALUES(XX_POST_NOTI_S.NEXTVAL,ITEM_TYPE, ITEM_KEY,ACT_ID,FUNC_MODE,SYSDATE);
COMMIT;
END;

--drop procedure procedure

BEGIN                       
WF_ENGINE.LaunchProcess(itemtype =>'XXWF_FUN',
                        itemkey  =>'11',
                        process => 'XXWF_FUNC_PROC' ,
                        userkey => 'A1',
                        owner   => 'EG_AFZAL');
END;      

select * from wf_notifications
where message_type = 'XXWF_FUN'
AND ITEM_KEY = 11


3.Imp Tables in Workflow.

SELECT * FROM WF_USER_ROLE_ASSIGNMENTS
SELECT * FROM WF_USER_ROLES
SELECT * FROM WF_ROLES
SELECT * FROM WF_ITEMS
SELECT * FROM WF_ITEM_ATTRIBUTES
SELECT * FROM WF_ITEM_ATTRIBUTE_VALUES
SELECT * FROM WF_ITEM_ATTRIBUTES_TL
SELECT * FROM WF_ACTIVITIES
SELECT * FROM WF_ACTIVITIES_TL
SELECT * FROM WF_ACTIVITY_ATTRIBUTES
SELECT * FROM WF_ACTIVITY_ATTRIBUTES_TL
SELECT * FROM WF_ACTIVITY_TRANSITIONS
SELECT * FROM WF_DEFERRED--WF_CONTROL

SELECT * FROM WF_ACTIVITY_ATTR_VALUES
WHERE NAME LIKE '%MASTER%'
AND PROCESS_ACTIVITY_ID
IN(
SELECT *-- PROCESS_ACTIVITY
 FROM WF_ITEM_ACTIVITY_STATUSES
WHERE ITEM_TYPE = 'ERP'
AND ITEM_KEY ='63865'
)

SELECT * FROM WF_ITEM_TYPES
SELECT * FROM WF_LOOKUPS_TL

SELECT * FROM WF_NOTIFICATIONS
WHERE MESSAGE_TYPE ='ERP'
ORDER BY BEGIN_DATE DESC

SELECT * FROM WF_NOTIFICATION_ATTRIBUTES
SELECT * FROM WF_MESSAGES
SELECT * FROM WF_MESSAGES_TL
SELECT * FROM WF_MESSAGE_ATTRIBUTES
SELECT * FROM WF_MESSAGE_ATTRIBUTES_TL
SELECT * FROM WF_ETS
SELECT * FROM WF_PROCESS_ACTIVITIES

LIST OF ACTIVITIES FOR AN ITEMTYPE
Accepts Workflow itemtype / shortname as input parameter and will all the activities involved along with the status and user name to whom the current activity is assigned.

SELECT A.ITEM_KEY,
       B.ACTIVITY_NAME,
       A.ACTIVITY_STATUS,
       A.ACTIVITY_RESULT_CODE,
       A.ASSIGNED_USER,
       A.BEGIN_DATE,
       A.END_DATE      
FROM WF_ITEM_ACTIVITY_STATUSES A,
     WF_PROCESS_ACTIVITIES B
WHERE A.PROCESS_ACTIVITY = B.INSTANCE_ID(+)
AND B.PROCESS_ITEM_TYPE = A.ITEM_TYPE
AND A.ITEM_TYPE = 'ERP'
AND A.ITEM_KEY = 64077
AND ACTIVITY_NAME IN ('PLANNING','PURCHASING','MFGFINANCE','CSD','TAX')

TO FIND FROM HOW MANY DAYS AN ACTIVITY IS PENDING

Accepts workflow itemtype and activity as input variables and the results will provide the time frame explaining from how long the activity is pending along with the username whose action is req

SELECT B.ACTIVITY_NAME,
       TRUNC(SYSDATE) - TRUNC(BEGIN_DATE) PENDING_FROM_NO_OF_DAYS,
       COUNT(B.ACTIVITY_NAME) TOTAL_PENDING
FROM WF_ITEM_ACTIVITY_STATUSES A,
     WF_PROCESS_ACTIVITIES B
WHERE A.PROCESS_ACTIVITY = B.INSTANCE_ID
AND B.PROCESS_ITEM_TYPE = A.ITEM_TYPE
AND A.ITEM_TYPE = 'ERP'
--AND A.ITEM_KEY = 1131
AND END_DATE IS NULL
AND ACTIVITY_STATUS != 'ERROR'
AND ACTIVITY_NAME IN ('PLANNING','PURCHASING','MFGFINANCE','CSD','TAX')
GROUP BY ACTIVITY_NAME,
TRUNC(SYSDATE) - TRUNC(BEGIN_DATE)
ORDER BY ACTIVITY_NAME,
PENDING_FROM_NO_OF_DAYS


LIST OF ACTIVITIES THAT ARE PENDING FROM N DAYS

SELECT SUM(TOTAL_PENDING) PENDING_LESS_THAN_5DAYS
FROM
(SELECT B.ACTIVITY_NAME,
       TRUNC(SYSDATE) - TRUNC(BEGIN_DATE) PENDING_FROM_NO_OF_DAYS,
       COUNT(B.ACTIVITY_NAME) TOTAL_PENDING
FROM WF_ITEM_ACTIVITY_STATUSES A,
     WF_PROCESS_ACTIVITIES B
WHERE A.PROCESS_ACTIVITY = B.INSTANCE_ID
AND B.PROCESS_ITEM_TYPE = A.ITEM_TYPE
AND A.ITEM_TYPE = 'ERP'
--AND A.ITEM_KEY = 1131
AND END_DATE IS NULL
AND ACTIVITY_STATUS != 'ERROR'
AND ACTIVITY_NAME IN ('PLANNING','PURCHASING','MFGFINANCE','CSD','TAX')
GROUP BY ACTIVITY_NAME,
TRUNC(SYSDATE) - TRUNC(BEGIN_DATE)
ORDER BY ACTIVITY_NAME,
         PENDING_FROM_NO_OF_DAYS ) FIVE_DAYS
WHERE FIVE_DAYS.PENDING_FROM_NO_OF_DAYS < 5

2.2 Components of Workflow and Architecture

Components of Oracle workflow process:

Item Type
Process
Attributes
Notifications.
Messages
Functions
Events
Lookup Types
Transition
Data Store




Item Type: Unique Name of the Workflow. (extension of workflow is .wf)
Grouping of workflow components into high level category.
Its like a parent.

Process:
its a picturial/graphical reprsentation of workflow process.
collection of activities and relation between activities.

Two types of process:

(i) runnable process:
A process which can be passed as a parameter to the workflow engine.

example 2 processes in the workflow, (permanent emp/ temp emp)
when perm emp applies perm emp process should be triggered.
temp emp applies temp emp process should be triggered.

(ii) non-runnable process:

Its only a processes, but not passing parameters in it.
calling sub processes ..

x, y two processes.

x by passing parameter (runnable process)
x calls y in the workflow process (y as a non-runnable process).

Attributes:

Its a global variable. to store the values.
And It is used to transfer the  exchange between workflow and database is done by Attributes.


Types of Attributes:
10 types available.
10 types of values can be stored . (char, number, date...etc)

Notifications:

Its a non-automated unit of work, which sends electronic information to receipent roles.

2 types of notifications:
FYI: for your information notification type. (only sending attributes, no response)
Todo or FYA For your actions notification type. (sending, response)

send atributes: leave type, no of days.. emp name...
respond attribures; approve/reject

1 workflow can have n number of notifications.


Messages:
That information of leave type, emp name ... dertails cannot be taken in notifications.
Message is container of information, which carries the notification.

Message 2 paarts
Subject :
Body: Actual information of the msg.

two types of bodies:

Text body.
HTML Body.

Relation between notification and message.
One notification can be attached to (access) only one message.
One msg can be attached to n number of notifications.

Functions:

Its a automated unit of work, which executes automatically.

(executing pl/sql procedure in the database from the workflow using funtions)

In the workflow Function we call the procedures from the database.
In the workflow Function we cannot call the functions or pl/sql  from the database.

for every function in the workflow, u need to specify the cost (how much time i need to execute the procedure of database).

Events:
Business Event means within the oracle applciation base on the event, (creating po, updating po) do something.

we can list all the event activities with the current item type.

Events can be raised by the form (updating po)
events can be raised during notification (shortage of stock after so is approved)

 raise , receive  or sent are 3 things done by the events.


Lookup Types:

Static list of values in the workflow.
Have to create manually the values in the lookup type in the worklow , then attach the lookup type in the workflow.

Transition:


used to join two independent activities.
It is denoted with the arrow symbol.

Data Store:

Which we are going to storesor process definition (item type)  is called data store.
Data store is a database or can be a flat file.

Storing in the database is called a database.
stroring in the flat file in desktop.


Directory Services:
set of views  (wf_users,wf_roles,wf_user_roles)
Using performer as afzal (user).

If storing in the attributes (as a variable), it dont use the directory services.
If not using directly the directory services (of class 1), it uses the directory servcies.




Workflow Arctiture:

1. Workflow builder
while installing workflow builder Workflow definition files.

e:/ora_home1/wf/data/us/
path.

Workflow definition files has have pre defined components, like start and end.
(same as library files attaching during the custom form builder)

Workflow loader:
download/upload

2.
Oracle sever: (database)

Workflow Engine..

In the architecture we can see two way process, of flow..

2. Workflow Notes

Version of Workflow:
select workflow_version from wf_versions

1.What is Workflow??
Leaves applied to HR manager, after approval attedances should be updated as leave,
and leaves remaining should detect automatically,
and also the requester should get the approval.

2  Types of activities in every business process:

1. Manual : which will required manual interactions.
2. Automatic: which will be automated.



In workflow also have manual, automatic.

Notifications: manual activity...(manager clicking approve/reject buttons)
Automated Activity: Detect the leaves,attendances. (pl/sql functions, proc, packages.)

We can address above by creating pl/sql procedure and call this.

Graphical Tool:
Will allow to design the process requirement graphically.

Workflow files are saved to database tier, like rdf,fmb saved in application tier and with extension as .wtf.
No need to register with oracle application, just deploy(create and save) in the database.

Oracle workflow components:



Oracle workflow Builder: Graphical Designing tool, users can create,modify, view a new workflow process.
2 parts in WF.
        1. Navigator Tree.-similar Object navigatory of forms/reports builder, where we can access componenets from centralized location.
        2. Process Diagram.-graphical/picturial representation of ur business process.
Workflow Engine: One of the key componenets of the workflow, the entire capacity of workflow will reside in workflow engine.
             wf_engine is package(procedures/functions) which is called as workflow engine.
             It is Part of database.
             If we want to execte workflow then we need to call workflow engine.
                         Pass the parameters what workflow engine will do, it will star the workflow process.
             Runtime process will be create.(same as request id for concurrent program)
                         After it will start executing the start activity, next to other activities (process).
                         It will never touches the manual activies, it executes only automated activies.
Cost:
For everyautomated activities, need a cost.
A cost is what is the amt of time i need to spend to complete the proces.(prioritise the activies ex:immediately,schedule)
workflow engine has a thresold value,default 50.
cost given ex: 60
cost <= thresold value, automatically it will execute immediate.
cost >= thresold value, will execute later.
2 parts
1. foreground engine.-all online activies.immediate activities.
2. background engne.-all offline activities , execution later.

Once the activities completed, will go to the next activity.

Cost factor example:
OM>Shipping transaction
closing the sales order line - foreground engine
onhand qty -foreground engine
transfer to receivable interface -we can transfer in the night also, so background engine.

Workflow engine treatement to non-automated activies:
Notifications/Blocking activity occurs with in the workflow process, workflow engine stops/hold the process for sometime,
and will wait someone will come and delivers the notifications.

each and every activiy wil be monitored/administred by workflow engine.
maintains the history by the workflow engine.(started time, end time, who started and so on)

Approve/Reject -Transactional path.
Approve= approve path
Reject = reject path

whenever reaches the end activity, workflow engine process will stop.

Workflow Definitions Loader:
its a utility program, to which we can upload/download from local machine the workflows to the server (database).

Notification System:
Workflow engine will tell the notification system to deliver the notification.
It delivers base on the predefine template (header, body, footer) to the receipient/set of users.
Once the user response will take the response and give to the workflow engine.
Then the workflow engine will start the other activity base on the results.

Notification Worklist:
is the list of open notifications waiting for an user response.
its a type of function, attached to the responsibility.
1. selfservice function.
2. form function.

Directory Services:

In notification we need to specity the receipent(to whom has to deliver). (users/resp/)
In notifiction cant understand the resp, it wil take from directory services.

Directory services is a part of oracle databae, which is implmeneted as a set of views.
wf_users,wf_roles,wf_user_roles. (this contain all the user info and resp)
which is mapped underline application directory repository. (means application creating users/responsibilites directly mapped to directory servides views)

wf_users,wf_roles open the view and check the tables.(moment we will update the tables, this views will be updated)

Notification system will pick which Predefine template picks the data from the directory services views.


Workflow Monitor:
Is a application service through which we can monitor and administer the status of the workflow.
Conc manager will monitors the conc programs.
Admin rights need to monitor the workflow process.(of all users)

Business Event System:
Req: new employee created in hrms, notification has to triggered to all users that new employee has employeed.
couple of ways we can initiate the workflow:
traditional: pl/sql, button,executing conc program (work flow engine)
business event: ex:creation of employee(business event system)

it is an application servcie, which communicates business events between applications.

Workflow XML Loader:

whenever we create business event, related will be uploaded/downloaded from server/local pc.
its same as data definition to transfer the files from local to server.
Business event will be converted into xml file and then we will upload to server.

Workflow Manager.

To manage the workflow, to hold/run the request process (request id)
Workflow is the part of oracle application Manager.
from which we can manage the services of the workflow.

-------------------------------------------------------------------------------------------------------------------




Creating and Calling Workflow, Language (US, AR):

Creating workflow in two ways.
top level: High level design
bottow up level: programmatical design

Top level : no need underline components (for notification msg is underline, for func pl/sql is underline components)

 only during the graphical process of digram.
 
Before saving/moving to database (before validation), it should have dependent components.

Bottom up level:
First creating underline components , then the process.

Calling env:

1. Conc program
2. oracle forms.
3. pl/sql procedures.
4. Triggers.

To set Language:

American_America.AL32UTF8  for english
AMERICAN_AMERICA.AR8MSWIN1256 for arabic set nls_lang key to use arabic text in workflow.


------------------------------------------------------------------------------------------------------------------




1.Workflow Builder 2.6.3.5 Installation, Setups, Errors

1. Download the Workflow Builder from the below link.

http://www.oracle.com/technetwork/database/options/winclient-101059.html

2. Install the same and follow the screens.

3.  For wf nls error:

Set NLS_LANG as an operating system environment variable:

1. Select Start - Control Panel - System
2. Select Environment
3. Set NLS_LANG parameter to AMERICAN_AMERICA.UTF8.


Or try this

1. define NLS_LANG Environment Variable on your PC, following below navigation :
For Windows
Start / Settings / Control Panel / System / Advanced / Environment Variables
Define new "System Variable" NLS_LANG and assign it the value AMERICAN_AMERICA.WE8MSWIN1252
Save

2. Bounce the PC

3. Try again database connection from Workflow Builder