Friday, June 3, 2016

Oracle Time and Labor: Validate the timecard using Time Entry Rules

Requirement

The business requirement is to validate the timecard at the time of submission to ensure that when the Expenditure Type is "Straight Time", then the user can enter times of only 4 or 8. If the user enter any value except for 4 or 8, then an error message should be displayed to the user as below.




Steps

1. Define a message

i. Navigate to Application Developer (Responsibility) --> Application (Menu) --> Messages (Menu)

ii. Define a new message with the below details

Name :- XX_HXC_ST_4_OR_8_ERROR
Text :- For Straight Time, the hours entered should be wither 4 or 8
Application :- Time and Labor Engine






   iii. Submit Concurrent program  "Generate Messages" with below parameters. This will actually generate the message.

2. Create PLSQL function

Create the below PLSQL function in the APPS schema. This function will return 1 if there are any entries which is not 4 or 8. Othereise, it returns 0. No parameters are required as the timecard attributes can be fetched inside the function using standard APIs






CREATE OR REPLACE FUNCTION xx_hxc_st_4_or_8_validate_func
 RETURN NUMBER IS
  l_attributes    hxc_self_service_time_deposit.building_block_attribute_info;
  l_timecard_info hxc_self_service_time_deposit.timecard_info;
BEGIN
  --Retrieve Attributes (Project, task, exp type etc)
  l_attributes := hxc_self_service_time_deposit.get_block_attributes;
  --Retrieve Timecar infor (Hours etc)
  l_timecard_info := hxc_self_service_time_deposit.get_building_blocks;

  FOR l_attrib_index IN l_attributes.first .. l_attributes.last
  LOOP
    --For Each record in attribute table
 
    IF (l_attributes(l_attrib_index).attribute_category = 'PROJECTS' AND l_attributes(l_attrib_index).attribute5 = 'ST' --Straight Time
       )
    THEN
   
      FOR j IN l_timecard_info.first .. l_timecard_info.last --Loop through each day
      LOOP
     
        --
        IF (l_timecard_info(j).time_building_block_id = l_attributes(l_attrib_index).building_block_id AND l_timecard_info(j).type = 'MEASURE')
        THEN
       
          IF NVL(l_timecard_info(j).measure
                ,0) NOT IN (4
                           ,8
                           ,0)
          THEN
            RETURN 1;
          END IF;
        END IF;
      END LOOP;
    END IF;
  END LOOP;

  RETURN 0;
END xx_hxc_st_4_or_8_validate_func;



3. Create function

To register the PLSQL function in HR, navigate to HRMS Superuser (R) --> Other Definitions --> Formula Functions. Create a new record with the below values.

Name :- xx_hxc_st_4_or_8_validate_func
Data Type :- Number
Class :- External function
Alias Name :- xx_hxc_st_4_or_8_validate
Description :-  xx_hxc_st_4_or_8_validate_func
Definition :-  xx_hxc_st_4_or_8_validate_func



4. Create fast formula

Define a fast formulae which can invoke the function defined in the above step and tie it with the message based on the return value.

Navigate to  HRMS Superuser (R) -->Total Compensation (M) --> Basic (M) --> Write Formulas (M). Enter the formula with the below values

Name :- xx_hxc_st_4_or_8_validate_ff
Type :- OTL Time Entry Rules
Description :- Time Entry 4 or 8 Hours





Click on Edit button and paste the below into the text box.

/* ****************************************************************
Processing for hours check
**************************************************************** */

ret_val = 0

ret_val = xx_hxc_st_4_or_8_validate_func()
               

IF ( ret_val = 0 )
THEN
        rule_status = 'S'

IF ( ret_val = 1 )
THEN
        ( rule_status = 'E'
          message1 = '
XX_HXC_ST_4_OR_8_ERROR')

/*  ****************************************************************
RETURN VARIABLE
**************************************************************** */

RETURN rule_status, message1



5. Create Time Entry Rule

To define a time entry rule which refers the fast formula, navigate to  Global OTL Application Developer (R) --> Time Entry Rules (M) --> Define Time Entry Rules (M). Create an entry with the below details.

Name :- Time Entry 4 or 8 Hours
Description :-  Time Entry 4 or 8 Hours
Usage :- Submission / Resubmission
Formula :- Time Entry 4 or 8 Hours







6. Create Time Entry Rule Group

To add the time entry rule to a time entry rule group, navigate to  Global OTL Application Developer (R) --> Time Entry Rules (M) --> Time Entry Rule Groups (M). Create an entry with the below details.

Group Name :- xxhxc rule group
Rule Name :-  Time Entry 4 or 8 Hours
Outcome :- Error





7. Attach the time entry rule group to Preferences

Final step is to attach the rule group to the user's preference. For this, navigate to  Global OTL Application Developer (R) --> Preferences (M). Identify the correct preference node and set the value of Time Entry rule to xxhxc rule group





8. Restart the server 

Test


Try entering a timesheet with hours other than 4 and 8 and check if error message is appearing.