Checks if a parent table has a relative record in a child table

Got something cool to share with AppGini users? Feel free to post it here!
Post Reply
fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Checks if a parent table has a relative record in a child table

Post by fgazza » 2021-05-15 17:01

Hello everybody.
I have a "parent_table" table which has two child tables named "child_table_1" and "child_table_2"
I need to create a "fill child table 1" button that appears only if there are no child records of the linked record in the "parent_table" table in the table "child_table_1".
To be clearer:
The "parent_table" table contains enrollments for a training course (one enrollment for each enrollee).
The "child_table_1" table contains the end-of-course questionnaire.
At the end of the course, when a participant opens their record in the "parent_table" table, they must see a "fill child table 1" button which will disappear when the participant has filled in the "child_table_1" relating to the specific course.

I ask for help setting the right code in the hook file!

THANK YOU!!!

Fabiano

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: Checks if a parent table has a relative record in a child table

Post by pbottcher » 2021-05-15 21:35

Hi,
what did you try so far. What is not working?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

fgazza
Veteran Member
Posts: 205
Joined: 2019-04-30 17:37

Re: Checks if a parent table has a relative record in a child table

Post by fgazza » 2021-05-16 11:45

Hello Pascal.
Sorry ... I didn't try to write the code. I do not know where to begin.

i tried to sketch this code but i don't know if i'm on the right path and i don't know how to go on anyway:

Code: Select all

if ($???????????????) {

/*above, instead of question marks, I have to define the condition to check, that is: does this record already have a child record in the table " child_table_1 " ? */
		
		ob_start(); ?>
		
		<script>
			$j(function(){
				<?php if($selectedID){ ?>
					$j('#parent_table_dv_action_buttons .btn-toolbar').append(
					'<div class="btn-group-vertical btn-group-lg" style="width: 100%;">' +
					'<button type="button" class="btn btn-info btn-lg" id="autorizza" onclick="fill_child_table_1()">' +
					'<i class="glyphicon glyphicon-pencil"></i> fill child table 1</button>' +
					'</div>'
					);
				<?php } ?>
				});
			
			function fill_child_table_1(){
			
			/*Here I should set up a function that opens a new record in "add" mode with the lookup field already precompiled with the reference to the parent record*/
			
			}
			
		</script>
		
		<?php
		$form_code = ob_get_contents();
		ob_end_clean();
		
		$html .= $form_code;
		
	}
Thanks a lot to those who can help me!

Post Reply