About the Author

Monday, 21 January 2013

Controlling Related Fields by Peoplecode


Most of you might be already familiar with this, but thought of sharing again.

We come across many scenarios where field property needs to be controlled by peoplecode to match with the business logic. I want to mention about controlling a related display field.

Say I have Employee Id as the control field and Name as the related display field. For user friendly behavior, I hide the Employee Id field and display only the related field. So the name is displayed on the page instead of the employee id which is difficult to understand.


Now I need to hide this name from the page based on some user actions. As you have thought it is a very simple job, just write a code as seen below.

RECORD.FIELD.Visible = False;


Here comes the complex scenario. Suppose I have my Project Manager Id and HR Manager Id on the same page. I want to display the name for both Project manager and HR manager. For that I assign the same related display field, say PERSONAL_DATA.NAME, to both the fields.

My requirement still remains the same. I want to hide only the name for the employee and the project manager and HR manager name should still be visible. But all the name fields are same (PERSONAL_DATA.NAME).

If I use the previous code, which name will become hidden? Employees, project manager’s or HR manager’s? It will hide only the name which comes first in the page order.

Here is a method to tackle it.

Say the display control fields be:

Employee – EMPL_ID
Project Manager – PROJ_MGR_ID
HR Manager – HR_MGR_ID


To hide the name of the employee you can use the below code.

Local Field &fRelDisplayField;
&fRelDisplayField = GetField(RECORD.EMPL_ID).GetRelated(PERSONAL_DATA.NAME);
&fRelDisplayField.Visible = False;


This will hide only the employee’s name and other two names will remain visible. To hide other fields replace EMPL_ID in the above code with appropriate field.

No comments:

Post a Comment

Note: only a member of this blog may post a comment.