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
| Parameter | Local variable | |
|---|---|---|
| Syntax | Param.Name | Local.Name |
| Scope | Shared between the calling and called activities | Only the activity that declared it |
| Typical use | Pass an input, return a result | Loop counter, temporary total |
| Visible on the clipboard | In the parameter page of the running activity | Not on the clipboard as a normal property |
A worked example
A bank activity CalculateInterest is called from a loan flow.
- The caller passes
Param.PrincipalandParam.Rate. - Inside, a step sets
Local.Yearsto 5 andLocal.Totalto 0, then loops, adding interest each year. - The last step copies the answer into the output parameter
Param.Interest. - Back in the caller,
Param.Interestholds the answer.Local.Totalis gone, because it never leftCalculateInterest.
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