Step 3: Click on FileNew to get a screen as shown below
Step 6: Fill it up with details show below
Click on OK. Ensure that the Runnable box is checked. This indicates that your process can be launched using the Workflow APIs
Step 13: Navigate to the node tab and ensure that the following details are entered
Click ok. You should be able to see this function in your process definition window now.
Step 14: Creating a Stop Activity. Create another function activity with the following details
You should be able to see the end activity in the process definition screen
Step 15: Now let us create a message. Close the process definition window. Under your item type select message. Right click and select New Message and enter the details as shown below
Step 16: Now create a notification that will use the message that you have created to send information to a recipient. Open up the Process Definition window for the Demo Process you had created in step 11. Right click on the screen and select new notification. Enter the details of the notification as follows:
Now click on Node tab
Step 18: Now click on FileSave AsSelect database and enter the login details . Click ok . It might take some time to save the workflow to the database
from ap_invoices_all where invoice_num = 'EX-1'; begin for c2 in sel_invoice loop l_item_key := c2.invoice_num || '/' || TO_CHAR(c2.invoice_id); x_WF_process_exists := WF_item.item_exist (l_Item_type,l_item_key); if x_WF_process_exists = false then begin wf_engine.createprocess(l_Item_type,l_item_key,'DEMOPROC'); wf_engine.startprocess(l_Item_type,l_item_key); commit; end; end if; end loop; end workflow_trigg; end workflow_pkg_new ;
Let us look at each line of this code in detail /*These are all the local variable declarations. Note the item type name has been hardcoded to what we selected as the internal name while creating the item type earlier. We have created one variable which will hold the item key . The last variable is used to check if the process if the item type , item key , process combination has been previously used. If yes then we dont need to do anything else we need to go about launching the workflow */l_Item_type VARCHAR2(10) := 'INVDMWRK'; l_item_key varchar2(100); x_wf_process_exists boolean;
This piece of code is used to generate the item key which must be unique for a given item type and process combination.l_item_key := c2.invoice_num || '/' || TO_CHAR(c2.invoice_id);
The next line of code checks if the item key currently being generated is indeed unique .x_WF_process_exists := WF_item.item_exist (l_Item_type,l_item_key);
If this value returns false then we enter further and the following lines get executedwf_engine.createprocess(l_Item_type,l_item_key,'DEMOPROC'); wf_engine.startprocess(l_Item_type,l_item_key); commit;
create_process API creates the process instance for the item type, item key combination and start process launches the process. Why we need two calls is something you will understand in the examples to come. Now that we have created the package, let us launch this procedure from an anonymous PL/SQL Block Step 21: Execute the following piece of code from SQL*Plus or any other Tool which you useBEGIN workflow_pkg_new.workflow_trigg; END;
Confirm that the block completed successfully with no exceptions Step 21: Now login into the application using the user name which you had provided against the Performer Name when creating the notification . You must see something like this as soon as you log in.
That ends our first workflow . If you have done this correctly then what follows will be really simple. Please ensure that this exercise is completed successfully before proceeding any further.
1. Understanding Item and Message AttributesThe notification that we created now is pretty plain and does not really carry any details of what the invoice created actually contains. Let us add two pieces of information here the invoice amount and the invoice number. Step 1:Use the workflow created in the step above and Save it as Exp_02.wft Step 2:Create two item attributes Open the item type definition and add two item attributes
Step 3:Now create two message attributes
Use the details in the boxes given below to create the two attributes
Note that both the properties of the Message Attributes above we see that the Source property has been set to Send. This means that this message attribute is being used to send information to the Notification recipient. We will look at how this can also be set to Receive and be used to collect a response from a recipient in the next example. The fact that the default value of each of these message attributes is the item attributes results in the following. You set the item attribute value in your program Since the message attribute copies its value from the item attribute this value automatically gets reflected in the message attribute You have used the message attribute in the message body (show below) and that results in this information getting delivered to the recipient of the notification to which this message is attached. Step 4: Modifying the Message Body to use the new Message Attributes
Right Click on the Message we had created in step 1 and click on Properties. Navigate to the Body tab of the message and fill in the details as shown below
Step 5: Save this workflow to the database Step 6: Now we have to modify the package body we had created in Example 1 to set the Item Attributes . Please note that setting item attributes results in the messages attributes getting set as well .create or replace package body workflow_pkg_new is PROCEDURE workflow_trigg is l_Item_type VARCHAR2(10) := 'INVDMWRK'; l_item_key varchar2(100); errmsg_tmp varchar2(255); invoice_num_tmp VARCHAR2(30); invoice_amount_tmp NUMBER; x_wf_process_exists boolean;
cursor sel_invoice is select invoice_id,invoice_num,invoice_amount from ap_invoices_all where invoice_num = 'EXP-2'; begin for c2 in sel_invoice loop l_item_key := c2.invoice_num || '/' || TO_CHAR(c2.invoice_id); x_WF_process_exists := WF_item.item_exist (l_Item_type,l_item_key); if x_WF_process_exists = false then begin wf_engine.createprocess(l_Item_type,l_item_key,'DEMOPROC'); wf_engine.setitemattrtext( itemtype => l_Item_type, itemkey => l_item_key, aname => 'INVOICE_NUM', avalue => c2.invoice_num); wf_engine.setitemattrnumber(l_Item_type,l_item_key,'INVOICE_AMT', c2.invoice_amount); wf_engine.startprocess(l_Item_type,l_item_key); commit; exception when others then errmsg_tmp := SQLERRM; dbms_output.put_line('error is' || errmsg_tmp); end; end if; end loop; exception when others then errmsg_tmp := SQLERRM; end workflow_trigg;
Step 7: Execute the following piece of code from SQL*Plus or any other Tool which you useBEGIN workflow_pkg_new.workflow_trigg; END;
Step 8: Confirm that the Performer you had mentioned earlier has received a notification.
2. Understanding Lookup Types , Lookup codes and Conditional TransitionsLet us add another piece of functionality here. Let this not remain a FYI notification . Let us make it FYA . In other words the notification
will have action buttons like Approve and Reject. With this lesson we will be able to understand the concept of lookup types , codes and how we can branch based on a simple condition like Approval or Rejection of a Notification. Step 1: Open the workflow you have created in the section above and save it as Exp_03.wft Step 2:As of now our workflow looks like this
Step 3: Firstly delete the transition from the notification to the End node. To do this simply click on the transition and hit Delete. Step 4:Now open the Properties of the Notification and set it as follows
Step 5: A result type indicates the possible outgoing transitions from a node. In this case there will be two possible outgoing transitions . One for Approval and the other for Rejection. You might be wondering from where this Approval result type came from . This is a seeded lookup type that comes along with the Standard Item Type you had loaded in the first workflow we created. To check this go back to the Workflow Builder and follow the screen shots given below:
So this simply means that the possible outgoing transitions are determined by the lookup codes under the lookup type which you have selected for the Result property in the notification. Let us now see how we can create these transitions Step 6:Create another End Activity node in your workflow. Do not forget to set the End value in the Start/End property in the node tab. So your workflow will now look something like this
Step 7: Right Click on the Notification and start dragging the mouse to one of the End Activity nodes. The moment you reach the End Node and try to release the mouse you will notice a pop-up as shown below
Select Approve and you will notice a transition with the label Approve has got created from the Notification to the End Node Repeat this step and select Reject this time when creating the outgoing transition to the other End activity node. So finally your workflow will look like this.
And we are nearly done !! Step 9: Create an AP Invoice with the Number EXP-3. Step 10:Compile the following package bodycreate or replace package body workflow_pkg_new is PROCEDURE workflow_trigg is l_Item_type VARCHAR2(10) := 'INVDMWRK'; l_item_key varchar2(100); errmsg_tmp varchar2(255); invoice_num_tmp VARCHAR2(30); invoice_amount_tmp NUMBER; x_wf_process_exists boolean; cursor sel_invoice is select invoice_id,invoice_num,invoice_amount from ap_invoices_all where invoice_num = 'EXP-3'; begin for c2 in sel_invoice
loop l_item_key := c2.invoice_num || '/' || TO_CHAR(c2.invoice_id); x_WF_process_exists := WF_item.item_exist (l_Item_ty