Normal Topic subform loop loses parent form field value (Read 815 times)
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
subform loop loses parent form field value
Feb 20th, 2018 at 5:13pm
Print Post Print Post  
Using Sesame 2.6

Parent form ORDERS has OrderForm number, key field.
Subform ORDERLINES is naturally linked to OrderForm.
OrderForm is Unique, Text
.
Record A is exported to be imported to new record.
Pgm calls menu to use menu tree to Add new record.
New Record B is added, then imports exported record A, all is OK.

OrderForm has old number 35592 (normal)
OnFormEntry updates new OrderForm number and other fields. 
New OrderForm number is L19448. (This is OK)
ORDERS record is saved.

Then process starts to update some fields in subform, including reference to new OrderForm number.

Value of OrderForm goes from L19448 back to 35592 when starting to step through the subforms loop.
THIS IS THE PROBLEM!

I now see new record B with blank OrderForm field, values on subform have old OrderForm values vs. new ones.

I get ERROR msg that cannot save record with OrderForm 35592 (expect that now because unique).  OrderForm value is blanked out by Sesame, record cannot be saved, etc.

Here is the code:
Code
Select All
WriteLn("Form Order, 269, before saving record: " + FormOrder)
			FormCommit("ORDERS")
WriteLn("Form Order, 271, after saving record: " + FormOrder)

 			// UPDATE LINE ITEMS IN COPIED ORDER
 			vTotalLines = @FormResultSetTotal("ORDERLINES")
 			For vCnt = 1 to vTotalLines
WriteLn("Form Order, 276, after starting FOR in SubForm: " + FormOrder)			// FormOrder is OK

 				FormResultSetCurrentPosition("ORDERLINES",vCnt)
WriteLn("Form Order, 279, after setting position on subform: " + FormOrder)		// FormOrder is NG

 				FormFieldValue("ORDERLINES","Record", vCnt, @TN(@XLookUpR(@FN,999999,"ORDERLINES!Record","Record")) + 1)
				FormFieldValue("ORDERLINES","AddedBy", vCnt, @ClientLocalValue("lsUserName"))  // was @UserID (@ClientLocalValue("lsUserName"))
 				FormFieldValue("ORDERLINES","ChangedBy", vCnt, "")
 				FormFieldValue("ORDERLINES","DateAdded", vCnt, @Date)
 				FormFieldValue("ORDERLINES","TimeAdded", vCnt, @Time)
 				FormFieldValue("ORDERLINES","DateChanged", vCnt, "")
 				FormFieldValue("ORDERLINES","TimeChanged", vCnt, "")
WriteLn("Form Order, 288, before updating subform FormOrder: " + FormOrder)
				FormFieldValue("ORDERLINES","ParentOrder", vCnt, FormOrder)
 				FormFieldValue("ORDERLINES","ParentRecord", vCnt, Record)
 				FormCommit("ORDERLINES")
 				Next			// Go to Next Line

 			//OrderNumber = vCopyOrder

//WriteLn("Form Order, 296, before saving record: " + FormOrder)

 			FormCommit("ORDERS")			// Save record
 			// End CopyForm routines
 			GlobalValue("gsCopyForm",0)	// Clear CopyForm flag
 



And here are the WriteLns to track the problem.  The numbers are program line numbers.
Code
Select All
Form Order, 252, before Security ON: L19448
Form Order, 255, after turning Security ON: L19448
Form Order, 269, before saving record: L19448
Form Order, 271, after saving record: L19448
Form Order, 276, after starting FOR in SubForm: L19448
Form Order, 279, after setting position on subform: 35592
Form Order, 288, before updating subform FormOrder: 35592
Form Order, 276, after starting FOR in SubForm: 35592
 



1.  How and Why does OrderForm lose its new value?
2.  How to keep the new value of OrderForm to pass to subform?
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: subform loop loses parent form field value
Reply #1 - Feb 20th, 2018 at 7:58pm
Print Post Print Post  
Assuming this code is on the Orders form and without being able to see the application in it's entirety, I would suspect perhaps NotifyForm() being set to prevent save on the Orders form.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: subform loop loses parent form field value
Reply #2 - Feb 20th, 2018 at 8:51pm
Print Post Print Post  
The only NotifyForm commands are to prevent Extended Mode and to prevent manually deleting SubForm records.

What additional info do you need to help diagnose this?
  
Back to top
 
IP Logged
 
Bob_Hansen
Senior Member
Members
*****
Offline


WOW, They have the Internet
on computers now!

Posts: 1861
Location: Salem, NH
Joined: Nov 24th, 2002
Re: subform loop loses parent form field value
Reply #3 - Feb 21st, 2018 at 5:50pm
Print Post Print Post  
I recall a problem similar to this a few years ago.  Don't recall the specifics.  Never found the cause, but I think I solved the symptoms by copying the problem element value to a Global Variable before the code that caused the problem.  Then, after the problem occurred, I used the Global Variable to reset the original element value where needed.
  



Bob Hansen
Sesame Database Manager Professional
Sensible Solutions Inc.
Salem, NH
603-898-8223
Skype ID = sensiblesolutions
Back to top
IP Logged
 
obfusc88
Full Member
***
Offline


No personal text

Posts: 194
Joined: Dec 17th, 2005
Re: subform loop loses parent form field value
Reply #4 - Feb 21st, 2018 at 9:43pm
Print Post Print Post  
Bob - Thanks.  I did that, made a GlobalValue with the FormOrder Value, and then tried to use the GlobalValue to populate the ParentOrder field on the subform.  Still did not get the value on the subform, even though the GlobalValue was correct.   But I determined that the ParentOrder was a Number field, and the original FormOrder was a String.  Turns out the String would not accept the Number, of course!  So, now I need to change the fields from Numbers to Texts. 

So, I have a temp workaround, that seems to work for this code section.  Uncomfortable about how this happens.

So, I can send the FormOrder to the subform if I make the GlobalValue, but I still do not understand why the original value  of FormOrder is blanked out?  How would I plan for this in the future?
  
Back to top
 
IP Logged