What is the difference between parameters and local variables? How are they used in an activity?

Activities need a way to pass values around. Pega gives you two: parameters and local variables. They look alike, but they have different lifetimes and different reach.

Parameters

  • Referenced as Param.Name.
  • Defined on the Parameters tab of the activity, as inputs and outputs.
  • They can be handed to another activity when you Call it, and the called activity can send values back.
  • They also exist in data transforms, sections, data pages and other rules, not just activities.

Local variables

  • Referenced as Local.Name.
  • Declared on the Pages & Classes or Local variables area of the activity.
  • They live only inside the activity that declared them. A called activity cannot see them.
  • Best for temporary counters and intermediate results.

Comparison

ParameterLocal variable
SyntaxParam.NameLocal.Name
ScopeShared between the calling and called activitiesOnly the activity that declared it
Typical usePass an input, return a resultLoop counter, temporary total
Visible on the clipboardIn the parameter page of the running activityNot on the clipboard as a normal property

A worked example

A bank activity CalculateInterest is called from a loan flow.

  1. The caller passes Param.Principal and Param.Rate.
  2. Inside, a step sets Local.Years to 5 and Local.Total to 0, then loops, adding interest each year.
  3. The last step copies the answer into the output parameter Param.Interest.
  4. Back in the caller, Param.Interest holds the answer. Local.Total is gone, because it never left CalculateInterest.

When to use which

  • Data that another activity must receive or return: parameter.
  • Scratch values that only this activity needs: local variable.
  • Data the whole case needs later: a real property, not either of these.

Interview tip

Say "parameters are shared between activities, local variables are private to one." Add the syntax and the loop example. Related: the step page and the Activity label.

No comments:

Post a Comment