NetTalk Central

Author Topic: NT6.10 still clears session values after lookup  (Read 6895 times)

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
NT6.10 still clears session values after lookup
« on: December 20, 2011, 08:01:20 AM »
I'm at it again.
I still see a problem with a look-up in a pop-up from a form.
After the look-up is complete, the session values for the primary table are cleared. This causes errors in later processing because the page depends on the session values to be stable. From the NetTalk book you can see that session values are to be depended on -
  • "... it’s important again to use session values rather than local variables most of the time."
  • "2.  In the Web it’s appropriate to use Session Values in Filters, not Variable values. "
  • "Remember the form is session value based, so the hide condition needs to use session values, not regular field values."

The attached example should show what is happening. or you can just go here - http://tinyurl.com/7h9n7re

Here is what to do to see the effect.
Open the website - it will display a list of invoices.
Click the shopping cart to add a line item to that invoice. - the update invoices page will be displayed (as an insert to the line items table)
You should see the 2 tabs. the top is the line item entry form usual fields - invoice id, item id price, quantity, and total
The bottom shows display fields of the session values for those line item fields. - Make a change in the item and the session values reflect what happens.

Now enter an item id - type in a 1, 2 or 3 - don't select from the look-up yet.
Hit tab and you will see how everything is updated.
Tab down and change the quantity. You will see your change and the total display
Try that a couple of times - works nice.

Now click the look-up button and select an item.
Tab down and change the quantity.
What happened to the Product, Price and Total?
Note - Sometimes the product id will be cleared before you get to tab down to the quantity. That is part of the same problem, but is inconsistent due to the nature of how threads get timed.

If you load the attached example, compile and run it on your own machine, start up DebugView and watch as you make the selection. You will see something similar to this -
The (#:#) shows the Session Id and thread number -

[20824] [netTrace][thread=3] (0:3)_Open.
[20824] [netTrace][thread=4] (0:4)_Open.
[20824] [netTrace][thread=3] (170104446:3)_UpdateLineItems START Stage =-Div
[20824] [netTrace][thread=5] (0:5)_Open.
[20824] [netTrace][thread=4] (170104446:4)_Close.
[20824] [netTrace][thread=3] (170104446:3)_FileToSessionQ:PRODUCT
[20824] [netTrace][thread=3] (170104446:3)_After Lookup gsv Pro:RRP=399
[20824] [netTrace][thread=5] (170104446:5)_UpdateLineItems START Stage =-SetPics
[20824] [netTrace][thread=5] (170104446:5)_UpdateLineItems START Stage =-InsertRecord-Init
[20824] [netTrace][thread=5] (170104446:5)_UpdateLineItems START Stage =-SetPics
[20824] [netTrace][thread=5] (170104446:5)_UpdateLineItems START Stage =-InsertRecord-StagePre
[20824] [netTrace][thread=5] (170104446:5)_UpdateLineItems PreInsert
[20824] [netTrace][thread=5] (170104446:5)_FileToSessionQ:C:\Documents and Settings\All Users\Documents\SoftVelocity\Clarion8\Accessory\Capesoft\NetTalk\Web Server\ParentChildBrowse (25)\LINEITEM.TPS
[20824] [netTrace][thread=5] (170104446:5)_UpdateLineItems START Stage =-FocusBack
[20824] [netTrace][thread=5] (170104446:5)_Close.
[20824] [netTrace][thread=3] (170104446:3)_Close.


In here you can see that Thread 3 is still processing the code after the lookup when thread 5 starts to refresh the page. Unfortunately, thread 5 continues and acts as though the insert just started so it does a call to PreInsert which, doing its good housekeeping, clears the session values in the call to FileToQueue.
Thread 5 closes, and thread 3 closes never knowing what just happened. :(

BTW - the same thing happens in NT 5 with just one exception - Thread 5 does not call PreInsert; it only calls the INIT to refresh the page.

I am interested in hearing from anyone having odd things happen after a lookup or actually NOT having this issue. Maybe it's me.

The attached example is taken from Example#25 ParentChildBrowse.
Set your port number in the INI file. g:PortNumber=88

I added embeds to watch and count threads as they are opened and closed and added those IDs to the trace outputs.

TIA
Chris C


[attachment deleted by admin]
Real programmers use copy con newapp.exe

John Fligg

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
    • Ambrit Software
    • Email
Re: NT6.10 still clears session values after lookup
« Reply #1 on: December 20, 2011, 08:49:49 AM »
I THINK but not sure if this is similar to a problem I am having where adding a record on one form and then a related on another seems to be losing the session variable.

I am not sure mine is related specifically to a lookup but I do believe that somewhere in the sequence the session variable is being "lost".

Mine seems to be the reverse in that a contactID is not being provided to a lookup on another "tab".

So add a contact on a form and then a related patient on a tab and the contact is not being picked up on Insert new patient. You have to save the contact record first, then edit it to be able to add related records.

Bruce was looking into this but not heard back if this was an issue with NT itself or my mistake.

John Fligg


ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: NT6.10 still clears session values after lookup
« Reply #2 on: December 20, 2011, 09:07:57 AM »
John,
In order to add children to a parent before the parent is saved, you may need to check "Prime Auto Inc even if not necessary" on the form's advanced tab.
That way the Parent Id is made available right from the start of the insert.

chris
Real programmers use copy con newapp.exe

John Fligg

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
    • Ambrit Software
    • Email
Re: NT6.10 still clears session values after lookup
« Reply #3 on: December 20, 2011, 02:28:40 PM »
Afraid no joy with that.

John

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: NT6.10 still clears session values after lookup
« Reply #4 on: December 20, 2011, 04:06:19 PM »
Just for fun, put a p_web._Trace in the preinsert routine. and watch debugview while you insert a record.
If you see it fire more than once, you may be seeing the same problem I am.

Chris
Real programmers use copy con newapp.exe

John Fligg

  • Sr. Member
  • ****
  • Posts: 361
    • View Profile
    • Ambrit Software
    • Email
Re: NT6.10 still clears session values after lookup
« Reply #5 on: December 21, 2011, 12:12:16 AM »
Good idea. No it only fired once. Cehcked tps file and ID there but not showing on insert so unrelated. Sorry.

John

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: NT6.10 still clears session values after lookup
« Reply #6 on: December 21, 2011, 01:09:12 AM »
Hi chris,

I have tried to follow your instructions as best I can, but I'm not getting the same effect as you. However I'm not sure that I'm even doing it right, because unfortunately your instructions are very imprecise. For example, in this paragraph,

>> Here is what to do to see the effect.
>> Open the website - it will display a list of invoices.
yes.

>> Click the shopping cart

there is absolutely no reference I can see anywhere to a shopping cart button here. I ultimately guess you meant "Press the Insert button" - but already I'm in doubt that we're looking at the same thing.

>> Click the shopping cart to add a line item to that invoice. - the update invoices page will be displayed (as an insert to the line items table)

putting UpdateInvoices and Insert together gave me some clue you were pressing the insert button. Suddenly though there is a jump.

>> You should see the 2 tabs. the top is the line item entry form usual fields - invoice id, item id price, quantity, and total
>> The bottom shows display fields of the session values for those line item fields. - Make a change in the item and the session values reflect what happens.

again I'm assuming that you pressed Insert again - this time on the LineItems browse. That seems to give the form you are describing.

>> Now enter an item id - type in a 1, 2 or 3 - don't select from the look-up yet.
(I presume you mean "product")

>> Hit tab and you will see how everything is updated.
>> Tab down and change the quantity. You will see your change and the total display
>> Try that a couple of times - works nice.

seemed to go ok.

>> Now click the look-up button and select an item.

does it matter which one? I assume not....

>> Tab down and change the quantity.
ok, changed to 2.

>> What happened to the Product, Price and Total?

After the lookup, the Product was set to the id code of the product I selected. (ie 1, 2 or 3)
After changing the quantity the product code and price remained unaltered, the total increased to the price * quantity.

Here's what happened in Debugview (and the corresponding log)

1. Press Lookup button. The log shows 2 incoming requests;
GET /SetSessionValue?popup_BrowseProducts=1&_ajax_=1
and
GET /BrowseProducts?_ajax_=1&Lookup_btn=1&_refresh_=sort&_popup_=1&LookupField=LIN__Product&_sort_=&undefined&LIN__Product=0
The first is a simple SetSessionValue being done as part of the popup so the server "knows" the browse is now visible in popup mode.
The second fleshes out the contents of the lookup itself.

In debugView we see the two threads being processed, asyncrounsly as expected.

[7928] [netTrace][thread=3] (0:3)_Open.
[7928] [netTrace][thread=4] (0:4)_Open.
[7928] [netTrace][thread=3] (810424615:3)_Close.
[7928] [netTrace][thread=4] (810424615:4)_BrowseProducts START
[7928] [netTrace][thread=4] (810424615:4)_Close.

to simplify the trace, I'll just select whatever item is highlighted in the lookup browse.

this results in 3 requests
GET /updatelineitems_LIN__Product_value?_popup_=1&_event_=1&value=8mSskHvB&_ajax_=1
GET /SetSessionValue?popup_BrowseProducts=0&_ajax_=1
GET /UpdateLineItems?_ajax_=1&_focus_=1&_popup_=1&_bidv=undefined&viewstate=&_EIPClm=&_action_=6&_from_=BrowseProducts&_calledfrom_=undefined

the first assigns the new value to the lookup field - in effect it's noting to the server that the value has changed. The 8mSs... contents of the value is an index to the BroweValue queue, and this translates into the Product Id 1.

The second tells the server that the lookup Browse has vanished (ie the opposite of the earlier SetSessionValue).

The third returns the focus to the UpdateLinItems form. (This runs the FocusBack routine in case there's anything you want to do there.)

the Debugview log now shows;

[7928] [netTrace][thread=3] (0:3)_Open.
[7928] [netTrace][thread=3] (810424615:3)_UpdateLineItems START Stage =-Div
[7928] [netTrace][thread=4] (0:4)_Open.
[7928] [netTrace][thread=5] (0:5)_Open.
[7928] [netTrace][thread=5] (810424615:5)_UpdateLineItems START Stage =-Init
[7928] [netTrace][thread=4] (810424615:4)_Close.
[7928] [netTrace][thread=3] (810424615:3)_FileToSessionQ:PRODUCT
[7928] [netTrace][thread=5] (810424615:5)_UpdateLineItems START Stage =-FocusBack
[7928] [netTrace][thread=3] (810424615:3)_After Lookup gsv Pro:RRP=199
[7928] [netTrace][thread=5] (810424615:5)_Close.
[7928] [netTrace][thread=3] (810424615:3)_Close.

time to change the quantity from 1 to 2. This is the point where my debugview seems to start radically differing from yours.

This results in a single request to the server
GET /updatelineitems_LIN__Quantity_value?_popup_=1&_event_=1&value=2&_ajax_=1

which is an expected notification that a field value changed. the Debugview looks like this

[7928] [netTrace][thread=3] (0:3)_Open.
[7928] [netTrace][thread=3] (810424615:3)_UpdateLineItems START Stage =-Div
[7928] [netTrace][thread=3] (810424615:3)_Close.

I'm not sure why you appear to be getting 3 requests when you change the quantity field. And I'm not seeing any flow into Pre-Insert at any stage in this whole process.

If you follow my pattern (_exactly_) do you get a different response? If so can you think of any reason why? I'm using Firefox for the test, but I don't expect any difference with another browser.  Is there perhaps an alternate _exact_ sequence to demonstrate the effect you are getting?

If anyone else would like to try your zip file I'd be interested in the results they see.

cheers
Bruce

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: NT6.10 still clears session values after lookup
« Reply #7 on: December 21, 2011, 04:41:52 AM »
Bruce
Thanks. Sorry for being so cryptic.
I said Update Invoices when I should have said Update Line Items. The idea is to add a lineitem to the selected invoice.
I'm a little surprised that you didn't see the Browse Invoices displayed with a column called Add Item with Shopping Cart buttons. See the attached image.
If you click on one of those shopping carts, you should go to the UpdateLIneItems page where you should see the lookup button . If you don't see the cart buttons, then that's a whole different problem.

Chris



[attachment deleted by admin]
Real programmers use copy con newapp.exe

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: NT6.10 still clears session values after lookup
« Reply #8 on: December 22, 2011, 05:04:05 AM »
ahh - yes, that is the missing part of the puzzle. The fact that the form is being called by a custom button is key to understanding the whole process.

There is a bug in the lookup button which was caused by the form being called in this way - I've fixed the bug in 6.11, so that should take care of that.

cheers
Bruce

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: NT6.10 still clears session values after lookup
« Reply #9 on: December 22, 2011, 05:31:59 AM »
Phew! I thought I was headed to Bedlam - thanks!
I'd love to know what you changed to make this work.

Can't wait for 6.11 to test it.

Chris
Real programmers use copy con newapp.exe

Bruce

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 11250
    • View Profile
Re: NT6.10 still clears session values after lookup
« Reply #10 on: December 22, 2011, 07:06:43 AM »
In Netweb.tpw (well, you asked!);

      #IF((%FormFieldPopupLookup or %gPopups='Yes') and (%gPopups <> 'No'))
        #IF(%FormFieldLookuptitle)
      packet = clip(packet) & p_web.CreateStdButton('button',Net:Web:LookupButton,loc:formname,,,'ntd.push(''%FormFieldLookupProcedure'','''&p_web._nocolon('%FormField')&''','''&p_web.translate(%FormFieldLookupTitle)&''',1,'&Net:LookupRecord&',''%FormFieldLookupSortField'',''%procedure'')',,,loc:fieldclass)
        #ELSIF(%FormFieldPrompt)
      packet = clip(packet) & p_web.CreateStdButton('button',Net:Web:LookupButton,loc:formname,,,'ntd.push(''%FormFieldLookupProcedure'','''&p_web._nocolon('%FormField')&''','''&p_web.translate(%FormFieldPrompt)&''',1,'&Net:LookupRecord&',''%FormFieldLookupSortField'',''%procedure'')',,,loc:fieldclass)
        #ELSE
      packet = clip(packet) & p_web.CreateStdButton('button',Net:Web:LookupButton,loc:formname,,,'ntd.push(''%FormFieldLookupProcedure'','''&p_web._nocolon('%FormField')&''',''Lookup'',1,'&Net:LookupRecord&',''%FormFieldLookupSortField'',''%procedure'')',,,loc:fieldclass)
        #ENDIF
      #else

Pretty obvious really - surprised you didn't figure it out... <g>...

ccordes

  • Sr. Member
  • ****
  • Posts: 384
    • View Profile
    • Email
Re: NT6.10 still clears session values after lookup
« Reply #11 on: December 22, 2011, 08:17:12 AM »
Aw - I KNEW it would be easy <G>
After changing the GB colors to use css in 5, I promised myself not to fiddle with the templates again. At least not until after Christmas...
 ::)
refresh 11's not up yet...
refresh refresh 11's not up yet...
refresh refresh refresh 11's not up yet...
« Last Edit: December 22, 2011, 08:18:56 AM by ccordes »
Real programmers use copy con newapp.exe