This topic is locked
[SOLVED]

Hide Add on Child Records (based on values from parent record)

7/17/2021 9:18:37 PM
PHPRunner General questions
J
JoeB7774 author

I have a time sheet program where the user can add detail (child) entries. The parent record is a 'Pay Period' (a two week period). If the current date is outside of the start/end dates of a pay period, I would like to hide the add button on the child records (disabling the ability to add new child records when the user is outside of the pay period). I have hiden buttons before on the same form but am unsure how to reference parent fields on the child form (how to hide a button on a child form based on the values from a parent form). Any help would be greatly appreciated. Thanks in advance.

A
acpan 7/18/2021

You can try this:

  1. Go to child table, before display event and obtain the dates from master table using getMasterRecord():

$data = $pageObject->getMasterRecord();
echo $data["start_date"] ." ". $data["end_date"];

More info on getMasterRecord(): https://xlinesoft.com/phprunner/docs/getmasterrecord.htm

  1. hide the Add button, go to page designer and click on the add button and look to the right for item_id, click the question mark icon to get the item id and put the code in before display event of child table :

if dates condition matched =>

$pageObject->hideItem("your_add_button_item_id");
(item_id could be add or inline_add if you have not changed it)

That's should work, If you need more advanced settings, check Security API and setAllowedPages, getTablePermission.

Hope it helps.

J
JoeB7774 author 7/19/2021

Thanks for the info. WOrks great. One other question ... I have two levels of child records (Parent - Child 1 - Child 2). How would a person reference the start/end dates on the Parent record from the Child 2 record. Same method?

A
acpan 7/19/2021

I think child 2 cannot see the parent because its parent is child 1.

In that case, store the parent values as session variables at child 1, and access the session values from child 2 instead.

J
JoeB7774 author 7/19/2021

That worked great. Thanks.