NetTalk Central

Author Topic: Adding a child record when header of parent is clicked  (Read 4333 times)

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Adding a child record when header of parent is clicked
« on: November 07, 2011, 10:46:36 PM »
Hi Bruce,

I think this one is for you.
I have a form with a parent/child browse situation..
When I click the header bar of the parent browse, the child browse refreshes to empty, as it should.
When I click the insertbutton, I get a popup insert form for a chld record.
The foreign key field in the child record however, is NOT primed with the p_web.gsv('Parentkey') value as there is none (the prime is done through the prime tab).
I know I could catch this one in the validation but do you have a more elegant solution for this?

Cheers,
Rene
Rene Simons
NT14.14

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: Adding a child record when header of parent is clicked
« Reply #1 on: November 08, 2011, 02:13:36 AM »
Hi,

I "solved it" bij putting:

if p_web.gsv('Parent:recordid') = ''
      loc:invalid = 'Child:Fieldname'
      loc:alert   = 'Inserting a child record is not possible when no valid perent is selected.'
end           

in embed   
  ! Start of "End of Stage-Case statement in Form"
  ! [Priority 5000]

Cheers,

Rene
Rene Simons
NT14.14

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Adding a child record when header of parent is clicked
« Reply #2 on: November 08, 2011, 05:02:26 AM »
I'm not sure i understand this bit;

>> The foreign key field in the child record however, is NOT primed with the
>> p_web.gsv('Parentkey') value as there is none
>> (the prime is done through the prime tab).

You are, or aren't doing a prime on the prime tab? the child is, or isn't, related to the parent?
What is the child browse filter set to?

cheers
Bruce



Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: Adding a child record when header of parent is clicked
« Reply #3 on: November 08, 2011, 10:29:29 AM »
Yeah,

Here is the language barrier kicking in.
The browses are related 1:N.
The foreign key field in the child record is the primary key of the parent.

What happens is:
I click (by accident) the header of the parent browse in the part where there's no sort link.
At that moment, the sessionvar for the primary parent key is nullified, which is about right because in fact no parent record is selected. Yet.

The child browse is refreshed but as the session var for the primary parent key is nullified, no matching records are found to be shown in the child browse.... Yet.

The insert button of the child browse is still available and when I click it, the insert_child_record_form pops up.
In the template for the child form, in the prime tab, i prime the foreign key field which refers to the parent record, using the session var for the unique parent key, which is nullified by clicking the header. In other words the foreign key also gets nullified.

In the meantime I fill out the child form and click save.
And voila, an orphan child record is created.

After that, when i accidently click the header of the parent browse, I get results in the child browse.

Imho this is a bug.

Cheers,
Rene
Rene Simons
NT14.14

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Adding a child record when header of parent is clicked
« Reply #4 on: November 08, 2011, 06:38:21 PM »
Have you tried putting a condition on the child insert button - probably the sessionvar for the primary parent key? That way you can't insert a child record unless you have a parent record.

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Adding a child record when header of parent is clicked
« Reply #5 on: November 08, 2011, 10:51:13 PM »
>> Imho this is a bug.

I agree. I've tweaked 5.41 so that clicking on the header accidentally does nothing. I think that stops the problem before it starts.

cheers
Bruce

Rene Simons

  • Hero Member
  • *****
  • Posts: 650
    • View Profile
Re: Adding a child record when header of parent is clicked
« Reply #6 on: November 09, 2011, 04:06:21 PM »
Hi guys,

Yes I did do a work-around but I prefer Bruce's solution. Ofcourse  :)

Thnks for your time.

Rene
Rene Simons
NT14.14