Oracle Fast Formulas - Chapter 22: Working with Fast Formula Functions in Oracle Fusion

 

Chapter 22: Working with Contexts in Oracle Fast Formulas

๐Ÿ” Introduction

In Oracle Fusion Fast Formulas, contexts act as dynamic variables that carry information from the system to your formula during execution. They allow formulas to behave differently based on who or what is being processed—like a specific employee, assignment, or payroll.


๐Ÿง  What Are Contexts?

Contexts are predefined variables passed automatically into your formula by the system. These hold values such as:

  • Assignment ID

  • Payroll ID

  • Effective Date

  • Element Type

  • Person ID

These variables help in writing flexible, scalable, and reusable formulas.


๐Ÿ“Œ Commonly Used Contexts

Context NameDescription
ASSIGNMENT_IDThe assignment being processed
PERSON_IDThe person for whom the formula is run
EFFECTIVE_DATEThe current processing date
ELEMENT_TYPE_IDThe type of element triggering the formula
PAYROLL_IDThe payroll under which the assignment is processed

๐Ÿ› ️ Syntax to Use Contexts

You typically use two statements with contexts:

plsql
DEFAULT FOR <CONTEXT_NAME> IS <DEFAULT_VALUE> <your_variable> = GET_CONTEXT('<CONTEXT_NAME>')

✅ Example

plsql
DEFAULT FOR PAYROLL_ID IS 0 payroll_id = GET_CONTEXT('PAYROLL_ID') IF payroll_id = 1001 THEN result = 1000 ELSE result = 0 ENDIF RETURN result

๐ŸšฆWhy Set Default Values?

If the context value is not passed to the formula, it avoids errors by using a default.


๐Ÿ“ Use Case Example

Let’s say you want to pay a bonus only if a person belongs to Payroll ID 300.

pl
DEFAULT FOR PAYROLL_ID IS 0 bonus = 0 IF GET_CONTEXT('PAYROLL_ID') = 300 THEN bonus = 5000 ENDIF RETURN bonus

๐Ÿ“š Best Practices

  • Always provide a default value using DEFAULT FOR.

  • Use GET_CONTEXT() instead of directly referring to the context variable.

  • Avoid hardcoding values unless business rules require them.

  • Comment every major logic step for clarity.


๐Ÿงช Practice Quiz

  1. What is the purpose of using DEFAULT FOR in a Fast Formula?

    • a) To increase speed

    • b) To add comments

    • ✅ c) To avoid errors when context is not passed

    • d) To beautify the code

  2. What function is used to read a context value?

    • a) READ_CONTEXT

    • ✅ b) GET_CONTEXT

    • c) FETCH_CONTEXT

    • d) CONTEXT_VALUE

No comments:

Post a Comment