Often your business rules require that a particular field prompt against different records depending on factors that are determined at runtime.

These factors might include:

  • Which component the field is on
  • Who the user is (OPRID)
  • The value of another field on the component

The example below uses the following business rules:

  • If Review Type is Employee Self Assessment, then Reviewer ID should equal EmplID and be disabled.
  • If Review Type is Supervisor, Reviewer ID should prompt PSU_SUPVR_VW.
  • If Review Type is Peer or Performance, Reviewer ID should prompt PERSONAL_DATA.

To start, look at how the variable prompt table works in an application.

picture1

 

If you change the value in Review Type and then prompt on Review ID.  Notice that the values returned when review type is Supervisor are different from the values returned when the Review Type is Peer or Performance.

What’s going on behind the scenes?

Open the record definition you want to set the prompt on:

picture2

Select Edit Type of Table Edit then set the prompt table edit to %FieldName.

The %EDITTABLE value maps onto a field on the derived/work record DERIVED.

The first field in DERIVED is EDITTABLE.  That usually works for your purposes.  Should you need to put more than one variable prompt table field on a component, there are fields called EDITTABLE2, EDITTABLE3, and so on.

If you use the field DERIVED.EDITTABLE, in the record definition you would enter %EditTable as the prompt table name, as shown above.

Add the DERIVED field to the page.

In order for PeopleCode to access the value in the field, it must be loaded into the Component Buffer, one way is to put it on the page.  Put it at the same level as the prompt table field.  You will probably want to make it invisible.

picture4

Ideally set the triggering field to Interactive Mode.

Open the page definition and edit the field Reviewer Type.

picture5

Select the Use tab.  Notice that the Allow Deferred Processing checkbox is deselected.  This field must be in Interactive Mode in order for the FieldChange PeopleCode to execute when the field is changed.

Add the PeopleCode to the component definition.

Open the relevant component and select the Structure tab. Right-click and choose View PeopleCode.

Select the program for PSU_EMP_RVW_RVR.RowInit.

Notice the code that populates the DERIVED field with the appropriate value based on the value of the REVIEW_TYPE.

picture6

Consider all the events in which your code needs to be placed.  Probably PreBuild or RowInit, and possibly FieldChange.


2016 Note:

The above code has the record names as pieces of text – it would be better if the record names were referenced as object properties so that if someone changes the name of the record your peoplecode will automatically update.

 

 

Advertisements