NetTalk Central

Author Topic: Update parent field when value entered in child  (Read 17748 times)

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Update parent field when value entered in child
« on: February 25, 2012, 02:31:07 PM »
Bruce,

     When I enter a value in a field in a child record, upon saving the child record I want to update a similar field in the parent record.  I used to use validate Insert/validate Update embed in an earlier NT version but in 6.21 this does not seem to work.  What is the recommended method to do this and the recommended embed?

Thanks,

Jeff King

« Last Edit: February 25, 2012, 02:34:06 PM by jking »

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: Update parent field when value entered in child
« Reply #1 on: February 26, 2012, 07:46:22 PM »
I found a solution.  The files are related so I placed the field from the child in the parent browse.  Now there is no need to try and update a coresponding field in the parent.
In addition, I can use this child field to conditionally complete other parent fields by coding in the 3 Inside Browse Loop embed.

Thanks,

Jeff

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Correction: Re: Update parent field when value entered in child
« Reply #2 on: February 27, 2012, 05:10:04 PM »
I was wrong here.  Using this method only updates the queue of the browse.  When I actually open the record the data has not been updated.  In my parent browse I place the following code in the SetQueueRecord embed:

If Pth:Pathology_Complete = 'Yes'
     Spe:Case_Number = Spe:Specimen_Source&'-'&Spe:Specimen_ID
End

     The parent file is Specimen.tps and the related child file is Pathology.tps.  In an earlier version of NT (I forget the actual version) I place the following code in the ValidateUpdate (Start) embed:

     Spe:Specimen_ID = Pth:Specimen_ID
     If Access:Specimen.Fetch(Spe:SpecimenID_key) = Level:Benign
          Spe:Case_Number = Spe:Specimen_Source&'-'&Spe:Specimen_ID
          Access:Specimen.Update()
     End

     This worked in the earlier NT version but not in NT 6.21.  The Spe:Case_Number field was filled in when I returned to the parent browse. Any thoughts?

Thanks,

Jeff King


kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Update parent field when value entered in child
« Reply #3 on: February 27, 2012, 06:28:39 PM »
I would add in some trace calls to find out the value of Pth:Specimen_ID - you may need to grab that from a GSV.

You also may need to add Access:Specimen.UseFile() to the start of your code below for your update statement to work.

bruce2

  • Full Member
  • ***
  • Posts: 108
    • View Profile
    • Email
Re: Update parent field when value entered in child
« Reply #4 on: February 27, 2012, 08:24:21 PM »
Post an example Jeff.

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: Update parent field when value entered in child
« Reply #5 on: February 27, 2012, 08:51:26 PM »
I confirmed that Pth:Specimen_ID has the correct value and that the Fetch returns 0 (level:benign).  I added the UseFile as well.   I have been trying other embeds but still no luck.

Jeff

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Update parent field when value entered in child
« Reply #6 on: February 27, 2012, 10:55:32 PM »
I would try something like

      p_web._trace('test specimen update')
     Access:Speciman.UseFile()
     Spe:Specimen_ID = Pth:Specimen_ID
     If Access:Specimen.Fetch(Spe:SpecimenID_key) = Level:Benign
          Spe:Case_Number = Spe:Specimen_Source&'-'&Spe:Specimen_ID
          If Access:Specimen.Update()
            p_web._trace('error updating specimen ' & errorcode() & ' ' & errormessage())
          End
     Else
       p_web._trace('cant find specimen id' & Pth:Specimen_ID)
     End

If the Trace does not return anything (past the first trace) then I would guess that the file is being updated again somewhere else with a different value/s

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: Update parent field when value entered in child
« Reply #7 on: February 28, 2012, 12:35:17 PM »
Kevin,

     When I do this, where do I see the messages/results?  Is this where I run Dr. watson and look for messages in the event viewer?

Thanks,

Jeff

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Update parent field when value entered in child
« Reply #8 on: February 28, 2012, 02:53:04 PM »
no, download and install debugview (google the name). If you're running x64 then download that version.

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: Update parent field when value entered in child
« Reply #9 on: February 28, 2012, 05:41:24 PM »
Kevin,

     Thanks...I have it now.  I ran debugview and saw the first message "'test specimen update".   Then saw two error messages:  UpdatePathology_xxx_validate and UpdateSpecimen_xxx_validate. 
     I have updated to the most recent NT (6.22) but still have this issue.  I have uploaded a file called RiskComp2.zip containing the log output and my app, should anyone wish to take a look.

Thanks,

Jeff

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Update parent field when value entered in child
« Reply #10 on: February 29, 2012, 02:13:57 AM »
nothing attached but at a guess, the last message seems to suggest specimen is updated after you have already updated overwriting your changes. I just wonder if you are not better saving Pth:Specimen_ID to a sessionvalue where you are currently trying to update the file and then just before the specimen file is updated via the system prime Spe:Specimen_ID with the sessionvalue?


jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: Update parent field when value entered in child
« Reply #11 on: February 29, 2012, 06:36:47 AM »
Kevin,

Sorry!  Here is the attached file, I hope.

Jeff

[attachment deleted by admin]

kevin plummer

  • Hero Member
  • *****
  • Posts: 1195
    • View Profile
    • Production Accounting and Software Payroll
Re: Update parent field when value entered in child
« Reply #12 on: February 29, 2012, 03:23:23 PM »
Hi Jeff,

I'm still on C6.3 so I can't help.

I do have C7 but ... lets not go there!

Kev

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: Update parent field when value entered in child
« Reply #13 on: February 29, 2012, 09:44:49 PM »
thanks for the example Jeff.
now all I need are instructions on what to do (how to login etc) - and then where to go, what to do to see the effect you want or aren't getting.

cheers
Bruce

jking

  • Sr. Member
  • ****
  • Posts: 419
    • View Profile
    • Email
Re: Update parent field when value entered in child
« Reply #14 on: March 01, 2012, 04:50:37 AM »
Bruce,

     Thanks for looking at this.  First, there is a button called Users on the web server main screen.  Use this to add a user, username goes in the email field and password in the password field.  I used admin/ admin.
     Log in and then click on Specimen in the first menu.  Enter any data you wish here.  Note the Pathology Complete check box defaults to No.  This is of course the parent file.  Next, go to the Pathology tab.  Insert a new record, entering any data you wish.  The idea here is for a Pathologist to enter data in multiple sittings.  When complete they are to mark Pathology Complete in the pathology data section.  When this is done, I would like three fields in the parent (specimen) file to be updated automatically.  First, the date should be set to the date pathology was completed.  Then the case number should be set to source + specimen ID.  Finally, pathology complete should be set to yes as it is in the pathology file.
     In an earlier NT version, I had placed the following code in validate update:

If pth:pathology_complete = 'Yes'
Spe:specimen_id = pth:specimen_id
Access:specimen.fetch(specimenid_key)
Spe:date = today()
Spe:case_number = spe:source&'-'&spe:specimen_id
Spe:pathology_complete='Yes'
End

   This does not seem to work in NT 6.22.  I hope I gave you enough here to get you started.

Thanks,

Jeff