Activity End and Exit Activity methods in pega

Sometimes an activity has to stop early: a validation failed, a record was not found, or the work is already done. Pega has two methods for this, and the difference is in how far the stop travels up the chain of activities.

Exit-Activity

Exit-Activity ends only the current activity and returns control to the activity that called it. The caller carries on with its next step.

Activity-End

Activity-End ends the current activity and every activity that called it. Nothing further runs in any of them.

The classic example

Suppose activity Alpha calls Beta, Beta calls Gamma, and Gamma calls Delta.

Delta runs...What happens
Exit-ActivityOnly Delta stops. Gamma resumes at its next step, then Beta and Alpha continue as normal.
Activity-EndAll four activities stop: Delta, Gamma, Beta and Alpha.

A worked example

A bank's ProcessPayment activity calls CheckLimits, which calls CheckDailyTotal.

  • If CheckDailyTotal finds the customer has no transactions today, it uses Exit-Activity. There is nothing to add up, so it simply returns and the limit check carries on with the next rule.
  • If CheckDailyTotal finds the account is frozen, it sets an error message and uses Activity-End. The payment must not go any further, so all the calling activities stop.

How to decide

  • Can the caller safely continue? Use Exit-Activity.
  • Must the whole procedure stop? Use Activity-End.

Common mistakes

  • Using Activity-End inside a shared helper activity. It quietly stops every caller, which is a surprising bug for the next developer.
  • Leaving data half-updated. If you use Activity-End after some steps have already changed the clipboard, clean up first or roll the change back.
  • Confusing Exit-Activity with the "Exit" iteration options on a loop step, which stop the loop only.

Interview tip

Give the Alpha, Beta, Gamma, Delta chain and say which activities end in each case. Related reading: Call vs Branch and the Activity label.

5 comments:

  1. Exit activity example plz mentioned

    ReplyDelete
    Replies
    1. In Pega an Exit Activity is an activity that can be used to stop the processing of the current step or flow and exit without continuing further It is typically used to terminate a process flow early under certain conditions like when a decision is made that further processing is unnecessary

      Here is an example of how to use an Exit Activity in Pega

      Scenario Using Exit Activity in a Flow

      Lets say you have a flow where you are checking if an applicant is eligible for a promotion If they are not eligible you want to exit the flow immediately without executing the subsequent steps

      Steps to Create and Use Exit Activity

      1 Create an Activity Exit Activity
      Go to the Records menu and choose Technical Activity
      Create a new activity For example ExitPromotionEligibility

      2 Define Steps in the Activity
      In the Steps tab you can define the logic for the exit condition Lets say you check an applicants eligibility If they are not eligible you can use the Exit method to stop further processing

      Example steps for the activity

      Step 1 Check eligibility
      Use a When condition to check eligibility eg ApplicantEligibility property
      Action If condition to check whether the applicant is eligible

      Step 2 Exit if not eligible
      If the applicant is not eligible use the Exit method
      Example action in the step Exit with an optional Exit Code eg NotEligible

      Example pseudosteps in the activity

      Step 1
      Action If
      Condition ApplicantEligibility false

      Step 2
      Action Exit
      Exit Code NotEligible this is optional but useful for logging or tracking the exit point

      3 Invoke the Activity in the Flow
      In your flow for example a Process flow you can call this ExitPromotionEligibility activity
      When the activity runs if the eligibility check fails it will invoke the Exit action and stop further processing

      4 Example Exit Activity Code

      java
      Step 1 Check eligibility
      If Property ApplicantEligibility false

      Step 2 Exit the activity if not eligible
      ExitNotEligible Optional exit code



      In this example
      If the ApplicantEligibility property is false the flow will exit immediately without executing the next steps
      You can optionally log or handle the exit by passing a custom exit code

      5 Testing and Debugging
      You can test the activity using the Tracer tool in Pega to ensure that the exit condition is being triggered correctly and that the flow is being stopped as expected



      Summary

      Exit activity is used to stop the flow processing immediately
      Typically its used when a condition is met and further processing is not required
      You define an exit in an activity using the Exit method in an activity step

      This approach ensures that once an exit condition is met the flow terminates without further steps being executed

      Delete