Thursday, September 28, 2017

How To Send Notification To Multiple Users

g) How To Send Notification To Multiple Users

Oracle Workflow roles are stored in the database, in the Oracle Workflow directory service.The performer can be an item type attribute that dynamically returns a role.To send a single notification(FYI/Actionable) to multiple users we have to use Role attribute as performer of that notification.The attribute value must be the internal name of a role. 

Here we will discuss how can we send a single notification to multiple users.

Basic Requirement
Our old requirement looks like "when a person applies for a leave it should go his/her supervisor for approval.Approver must be able to provide his/her approval/rejection comments. The comments must be entered by the approver while rejecting the leave requisition.If he/she rejects the leave requisition without entering comments, then it should raise an application error.If he/she approves the requisition it should be optional.Approver must also be able to select theOrganization Leave Type from a list of values . If the leave gets rejected, don’t store any information in database.The approver should able to view/edit the person "Special Information Types" before approving the leave request.Before approving the sick leave request the approver must able to see the submitted medical document."

Now we will twist our original requirement- Instead of going to Supervisor for approval, all the leave request must go to the following identified people
  • ROLE1_APPR (User name of the person)
  • ROLE2_APPR (User name of the person)
  • ROLE3_APPR (User name of the person)
Solution Approach
First we will discuss about the changes that we need to do in workflow Definition.

A) Workflow Part
1) Load the latest workflow definition from database.
2) Create an item attribute of Type Role
 Internal Name:- XX_TEST_ROLE
 Display Name:- Test Role for Approval
 Type              :- Role

3) Now we have to add this newly created role to the performer of the notification (Initially it was Supervisor User Name). Now open the process (in our case it will be "Test Leave Approval Process"). Open the notification and go to the "Node" tab. Modify the performer.

4) Validate your design and save it to database.

B) Role Definition create Part
    Role can be defined and used in worklfow in two different ways.
          a) Create a Global Application Role
          b) Create database Adhoc Role

We will first discuss how can we define Role from Oracle Application and use the same in workflow.

a) Create a Global Application Role and its usages in workflow
    i) Go to UK HRMS Manage >> Transaction Maintanance >> Global Roles
   ii) Create your custom Global Role and add the desired users (Users must have a valid active fnd_user entry). Save your definition.
  
  iii) Our Application Role definition creation is complete now we have to set the value for our newly created Role attribute. The value of the Role attribute should be the
      name of the role. Workflow engine will take the names from the role and will send the notification automatically.
     We will set the value for Role attribute in our Trigger workflow procedure (Where we are setting the other attribute values)
      To set the Role attribute we need to call wf_engine.SetItemAttrText procedure. This will internally check for Role attribute(though this utility is for setting Text attribute) and perform the task accordingly.

   iv) Now compile the package and workflow is ready to trigger.


b) Create database Adhoc Role and usages
  Instead of creating a Global Role from application we can also create an database adhoc role and use the same to send notification.
   i)  Create a adhoc Role using wf_directory.CreateAdHocRole ultility. This will create a role in database,.

wf_directory.CreateAdHocRole(role_name                      in out varchar2,
                                              role_display_name        in out varchar2
      language                      in varchar2 default null,
     territory                         in varchar2 default null,
     role_description             in varchar2 default null,
     notification_preference   in varchar2 default ’MAILHTML’,
     role_users in varchar2    default null,
     email_address               in varchar2 default null,
     fax in varchar2               default null,
    status in varchar2           default ’ACTIVE’,
    expiration_date in           date default null,
    parent_orig_system        in varchar2 default null,
    parent_orig_system_id    in number default null,
    owner_tag                      in varchar2 default null
);


Enter the value for "role_name" (Must not be more than 320 character and keep the name in uppercase) and "role_display_name" parameter. Keep the other parameter to its default value.

If you want to make this role inactive after definite time period enter value for it (Ex:- for 365 days it should be sysdate+365. Means after 365 days role will be expired).

Here 
role_name             =>XX_TEST_ADHOC_ROLE
role_display_name=>Test Adhoc Role

 ii) Add the user to the newly created Role using wf_directory.AddUsersToAdHocRole utility.
wf_directory.AddUsersToAdHocRole(role_name in varchar2,
                                                     c in varchar2
                                                     )
Here 
role_name  => Internal name of the role 
role_name  => User name of the list of users that we need to add. The user name of the users must be either comma/space separated.
  
  iii) Now set the Role attribute value. The value of the Role attribute should be the Internal name of the adhoc role
      To set the Role attribute we need to call wf_engine.SetItemAttrText procedure. This will internally check for Role attribute(though this utility is for setting Text attribute) and perform the task accordingly.

   iv) Now compile procedure and workflow is ready to trigger.


Note:- 1) As we see we can define Role in two ways 1) Global Application Role 2) Database Adhoc Role.
              When we have a identified static list of approver/stakeholder to whom we need to send the notification we will use the Global Application 
              Role. It is easy to maintain.
              When we have a dynamic list of approver/stakeholder (if our requirement is something like send the notification to all the people who are in a
              particular grade) to whom we need to send the notification we will use the database adhoc Role.

2) If we check the "Expand Roles"(Double click on notification >> Notification Tab) check box it will send an individual copy of the notification message to each user in the role(The notification id will be different). The notification remains in a user’s notification queue until the user responds  or closes the notification.
Since this is a actionable notification and we are not using voting activity thus "First responder Win" happen.
If any of the role performer acts on the notification it will "Closed" in his/her queue. Whereas other will see it as "Cancelled".

3) Oracle Workflow does not support including the action history in a notification with the Expand Roles check box selected, which causes a separate copy of the notification to be sent to each user in the recipient role.


References:-                1) https://metalink.oracle.com
                                      2) Oracle Workflow Developer's Guide ( Release 12) B31433-04
                                      3) Oracle. Workflow API Reference Release 2.6.3.5 Part No. B12163–02
                         
Disclaimer:- This is a knowledge sharing site. This topic talks about a custom solution. Oracle Corporation may not provide you a support for any data corruption or any other problem in your custom code/problem arises because of the custom code. 
The author is not responsible for any kind of  system/data problem appears because of usages of this code.Reader/implementer must do it on his/her own risk/responsibility.Oracle Corporation may change API definition/usages. User must read the necessary documentation before using Oracle provided APIs.

No comments:

Post a Comment

Oracle Fusion - Cost Lines and Expenditure Item link in Projects

SELECT   ccd.transaction_id,ex.expenditure_item_id,cacat.serial_number FROM fusion.CST_INV_TRANSACTIONS cit,   fusion.cst_cost_distribution_...