NetTalk Central

NetTalk Web Server => Web Server - Ask For Help => Topic started by: jking on February 25, 2012, 02:31:07 PM

Title: Update parent field when value entered in child
Post by: jking 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

Title: Re: Update parent field when value entered in child
Post by: jking 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
Title: Correction: Re: Update parent field when value entered in child
Post by: jking 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

Title: Re: Update parent field when value entered in child
Post by: kevin plummer 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.
Title: Re: Update parent field when value entered in child
Post by: bruce2 on February 27, 2012, 08:24:21 PM
Post an example Jeff.
Title: Re: Update parent field when value entered in child
Post by: jking 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
Title: Re: Update parent field when value entered in child
Post by: kevin plummer 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
Title: Re: Update parent field when value entered in child
Post by: jking 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
Title: Re: Update parent field when value entered in child
Post by: kevin plummer 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.
Title: Re: Update parent field when value entered in child
Post by: jking 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
Title: Re: Update parent field when value entered in child
Post by: kevin plummer 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?

Title: Re: Update parent field when value entered in child
Post by: jking on February 29, 2012, 06:36:47 AM
Kevin,

Sorry!  Here is the attached file, I hope.

Jeff

[attachment deleted by admin]
Title: Re: Update parent field when value entered in child
Post by: kevin plummer 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
Title: Re: Update parent field when value entered in child
Post by: Bruce 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
Title: Re: Update parent field when value entered in child
Post by: jking 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

Title: Re: Update parent field when value entered in child
Post by: jking on March 01, 2012, 04:53:17 AM
Bruce,

I forgot to add to the code, access:specimen.update().

Thanks,

Jeff
Title: Re: Update parent field when value entered in child
Post by: Bruce on March 01, 2012, 05:41:03 AM
so are you saying you're all sorted now?
Title: Re: Update parent field when value entered in child
Post by: jking on March 01, 2012, 07:19:49 AM
Bruce,

     No, not sorted out yet.  I meant I forgot to add it to the sample code above.  I still have this problem.

Thanks,

Jeff
Title: Re: Update parent field when value entered in child
Post by: Bruce on March 01, 2012, 07:29:03 AM
ok, then - see my earlier note - working from your example I need to know what to do (how to login etc) to see the effect you're looking at/for.
Title: Re: Update parent field when value entered in child
Post by: jking on March 01, 2012, 10:18:24 AM
Bruce,

     Please see reply #14 of this thread, it explains how to log in and the effect I'm looking for.

Thanks,
Jeff
Title: Re: Update parent field when value entered in child
Post by: Bruce on March 01, 2012, 10:33:24 PM
ahh - missed that.
ok, first a couple of basic errors to sort out.

a) It's not recommended to display primary key component fields on the form as "string" fields. You've got them as auto-number, and "read only" - but it's still a bad thing to have them there as "Strings" or :"Numbers" - Change them to "display" if you want to display them (at least for early development) in the long run hide them away completely. To be fair, while this was a hard "rule" in NT4, it's no longer the case, and these days read-only fields are ok, nevertheless it's considered "poor form".

b) pth:Pathology_complete field, client-side tab, "on focus" - refresh value - tick this off. (It's just wrong.)

>> When complete they are to mark Pathology Complete in the pathology data section.

your data layout seems a little strange. So you have a field in the Pathology table, which is really a short-cut for the user setting the "path complete" setting in the specimen table? I suppose I should ask why they don't just set the spe:path_complete on the UpdateSpecimen table. I mean, you could put the field on the Pathology tab and everything. It seems to me it'd make more sense there. But ok, I'll presume there's some logic in your layout, so....

you have 2 problems;
(we'll ignore the fact that they can in fact change the pathology records after selecting that field.)

a) the specimen record may not have been written to disk at all at that point. If you're doing an insert then the parent record has been created, yes, but is currently blank.

b) the form is still open for UpdateSpecimen, so changing the record on disk would be useless, as it'll shortly be overwritten.

No, in the ValidateUpdate routine, all you can do is

  p_web.SSV('spe:date',today())
  p_web.SSV('Spe:case_number',  p_web.GSV('spe:source') & '-' & p_web.GSV('spe:specimen_id'))
  p_web.SSV('Spe:pathology_complete','Yes')

setting the current session values, and using the existing session values where existing values are required.

Your next issue is refreshing the other fields on the _specimen form_ when the _pathology form_ is completed.
That's a fair bit trickier, so perhaps take on board all the above, then repost your example with the changes etc, so we can take it further.

cheers
Bruce



Title: Re: Update parent field when value entered in child
Post by: jking on March 02, 2012, 08:39:16 AM
Bruce,

Thanks for taking the time with this.  I really appreciate your input.  Here are my comments:

a.  This is a test app and I have the primary key component fields displayed just for my reference during development.  These will be removed/hidden in the final app.

b.  Yup, just a left over setting I was testing.  I tried a number of different things trying to get the effect I was looking for.  This will be cleaned up.

     I have two (redundant) Path complete fields mainly for convenience at this point.  Two people will be involved in data entry.  An assistant will create the record in specimens.  Then a Pathologist will complete the pathology record, possibly coming back a number of times before deciding the record is complete.  This field should only be set by the pathologist, not the assistant.  
     I like your idea of placing the specimen path complete field on the path form.  I had not thought of this and thus I can remove the path complete field from the pathology file.  The Pathologist can set this field when ready, and I can display it in the specimen browse as well so the assistant does not need to look elsewhere for the  complete status.
     I would like to lock the pathology record when complete, preventing any changes, except perhaps by the Pathologist.  I think I can accomplish this by adding SecWin.  Finally, the other specimen variables can be set as you suggested, upon update validation or upon entering Yes in the specimen path complete variable (I actually have this working in my current version.

Thanks for all your input.

Jeff

Title: Re: Update parent field when value entered in child
Post by: jking on March 02, 2012, 09:21:41 PM
Bruce,

     I have attached an updated version of the app, with the same dictionary as before.  I changed the id number fields to display as recommended but just for development.  I have removed all the previous embed code I tried to get the specimen path complete to refresh after the path form was completed. 
     You mentioned getting the fields on the specimen form to refesh after the path form changes was trickier.  Can you provide some direction here?
     Also, this particular copy of the app has developed a problem.  I find login no longer works as expected.  The index page does not update properly nor can I call the main browse.  The login form keeps appearing.  I have noticed this many times before after numerous recompiles and I resolve this by using a backup copy.  However, I feel there is a problem here that needs fixing.  My embed code in the login form has not changed at all.  This is the code that does a lookup into the user file.  Can you take a look at this as well?  As I said I have other versions of this app where the login works as expected. 

Thanks,

Jeff

[attachment deleted by admin]
Title: Re: Update parent field when value entered in child
Post by: bruce2 on March 03, 2012, 03:16:40 AM
Force the webserver procedure to regenerate- typically by changing some setting or other on it.
Title: Re: Update parent field when value entered in child
Post by: jking on March 03, 2012, 04:40:42 AM
Bruce2,

     Thanks!  That seems to have fixed the login problem.

Jeff