Hot Topic (More than 10 Replies) Needs help with xResultsetReparent ( ) command (Read 2536 times)
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Needs help with xResultsetReparent ( ) command
Feb 29th, 2012 at 12:59pm
Print Post Print Post  
I have been using the code to make a document subrecord and then reparent it to the mainform. It works fine when I execute from the Layout in the different database but if it is initiated from the Layout of the same database where this subform belongs to, it does not add the subrecord in the form. The subrecord is made but it does not get reparented.  When I execute the same code from different database form, the earlier subrecords also shows up along with the new subrecord created.
Code
Select All
vChildRSID = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart==")

							If vChildRSID > -1 then
								{
									xResultSetCreateNewRecord (vChildRSID)
									xResultSetValue (vChildRSID, "RecNumber", vRecNumber)
									xResultSetValue (vChildRSID, "DateAdded", vDateAdded)
									xResultSetValue (vChildRSID, "Chart", vChart)
									xResultSetValue (vChildRSID, "Description", vDescription)
									xResultSetValue (vChildRSID, "View", vView)
									xResultSetValue (vChildRSID, "FileName", vFileName)
									xResultSetValue (vChildRSID, "Key", vKey)


									xResultSetClose (vChildRSID)

								}

							vParentRSID = @XResultSetSearch(@FN, "Index", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)
								/*

								If @XResultSetLocked (vParentRSID) = 1 Then
									{
										@MSGBox ("Parent ResultSet is Locked", "The Document will not go to DocumentSubform", "Process it from Other Database")

									}
									Else If @XResultSetLocked (vParentRSID) = 0 Then
									{
										WriteLn ("Parent ResultSet is Not Locked")

									}
								*/



							If vParentRSID > -1 then
								{
									vRecordsFound = @XResultSetTotal (vParentRSID)
									If vRecordsFound = 1 then
										{
											vChildRSID = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)

											If vChildRSID > -1 then
												{
													//WriteLN ("You were in ChildRSID")
													//WriteLN ("Total subrecords are " +   @Str (@xResultSetTotal (vChildRSID )) )
									                                xResultSetSort (vChildRSID, "DateAdded:1")
													xResultSetReparent (vParentRSID, "DocumentSubForm", vChildRSID)



													xResultSetClose (vChildRSID)
												}
										}
										Else if vRecordsFound = 0 then
										{
											WriteLN ("Chart " + vChart + " Does not exist in INDEX Database!!! Please Correct it" )
											vFailureIndicator = 1
										}
										Else if vRecordsFound > 1 then
										{

											WriteLN ("Chart " + vChart + " has Multiple Entries in INDEX Database!!! Please Correct it" )
											vFailureIndicator = 1
										}

									XResultSetClose (vParentRSID)


								}
							xResultSetClose (vChildRSID)       // for additional precaution - in case if it is not closed
							xResultSetClose (vParentRSID)		// for additional precaution - in case if it is not closed


 



I have tested to the extent that neither Parent nor Child resultsets gets locked up, still the xResultsetReparent ( ) command fails to work when executed from the database form where this subform is located.  The subrecord is made properly but does not show up in the subform.

I cannot use @FormfieldValue ( ) to fill up the subform record as the form that has the subform is usually not open and this code is initiated from the different form of the same database.

How can I make the code work when it comes to be executed from the same database form? Any suggestions?
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #1 - Feb 29th, 2012 at 8:48pm
Print Post Print Post  
Hello Bharat,

If you un-comment the line that says
Code
Select All
WriteLN ("Total subrecords are " +   @Str (@xResultSetTotal (vChildRSID )) ) 


and run it from the documents database do you get the correct number of child records or is it missing the newly added one?

-Ray
  

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


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #2 - Feb 29th, 2012 at 9:20pm
Print Post Print Post  
Ray, thanks a lot for looking into this.
It is missing the newly added one, if I do this from any form that belongs to the database to which the subform belongs. If the same code is executed from other database form, it will not miss the newly added one. The number that it shows as number of subform records will always be correct, meaning subrecord get formed but does not get parented properly if code is run from the subject database form.

Am I clear?
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #3 - Feb 29th, 2012 at 9:31pm
Print Post Print Post  
Also, if I run the code from the form that has the Document subform and fill it up by creating @FormNewRecord ( ) and filling out the fields with Formfieldvalue ( ), it works well and adds the subform record as expected. Ofcourse, I had to modify notifyform (7) code that was interfering with the code earlier but Erika kindly pointed out the problem.
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #4 - Feb 29th, 2012 at 9:43pm
Print Post Print Post  
To clarify even further, if I have any form belongs to the database to which the Documents subform is attached, open with the subject record (Does that lock the record?), and if I try to create and re-parent the subrecord even from other database forms, it will not reparent that subrecord and consequently, it will not show up in the subform.

However, the code to see if the parent handle (ParentRSID) is locked, it will show that it is not locked.  Embarrassed
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #5 - Mar 1st, 2012 at 2:16pm
Print Post Print Post  
Bharat_Naik wrote on Feb 29th, 2012 at 9:43pm:
However, the code to see if the parent handle (ParentRSID) is locked, it will show that it is not locked.  Embarrassed


It won't show as locked as it's open by the same client. If would show as locked if it was open by a different client.

Can you shoot an e-mail over to support@lantica.com with your sesame.ini file attached to it?

-Ray
  

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


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #6 - Mar 3rd, 2012 at 8:16am
Print Post Print Post  
Code
Select All
var vRS as Int
var vCRS as Int


vRS = @XResultSetSearch(@FN, "Index", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + Chart)
If vRS > -1
{
	vCRS = @XResultSetSubSet(vRS, "DocumentSubform")
	If vCRS > -1
	{
		XResultSetCreateNewRecord(vCRS)
		XResultSetValue(vCRS, "Description", "test record")
		XResultSetReparent(vRS, "DocumentSubform", vCRS)
		XResultSetClose(vCRS)
	}

	XResultSetClose(vRS)
}

 



Hi Ray,
I once again tested the above code placing in command button.  If I run the above code from any form (of course other than the form with the subform) that belongs to Parent database, the reparenting part will fail. The subrecord is made but just does not show up in the naturally linked subform.  But if the code is run from any form that belongs to database other than parent database, the subform record is made and also shows up in naturally linked subform.

I am afraid, the result of this test is consistent with my earlier experience.
  
Back to top
 
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #7 - Mar 5th, 2012 at 10:01pm
Print Post Print Post  
Bharat_Naik wrote on Mar 3rd, 2012 at 8:16am:
Hi Ray,
I once again tested the above code placing in command button.  If I run the above code from any form (of course other than the form with the subform) that belongs to Parent database, the reparenting part will fail. The subrecord is made but just does not show up in the naturally linked subform.  But if the code is run from any form that belongs to database other than parent database, the subform record is made and also shows up in naturally linked subform.

I am afraid, the result of this test is consistent with my earlier experience.


With the parent form open is the parent record that is getting the new child part of the retrieved result set, even if it is not the current record?

-Ray
  

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


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #8 - Mar 5th, 2012 at 10:04pm
Print Post Print Post  
Any work around?  Could it be changed in the future?
  
Back to top
 
IP Logged
 
Hammer
YaBB Administrator
Lanticans
*****
Offline


Fire bad. Tree pretty.

Posts: 3436
Location: Ohio
Joined: Nov 22nd, 2002
Re: Needs help with xResultsetReparent ( ) command
Reply #9 - Mar 5th, 2012 at 10:46pm
Print Post Print Post  
Bharat_Naik wrote on Mar 5th, 2012 at 10:04pm:
Any work around?  Could it be changed in the future?

Ray's post is a question, Bharat, not a statement.
  

- Hammer
The plural of anecdote is not data.
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #10 - Mar 5th, 2012 at 10:59pm
Print Post Print Post  
Thanks Erika for clarifying..  Parent form with the subform is not even open. New child record (subform record) is prepared in the resultset, that is to be reparented to the the form with subform so that it shows up in subform.

Am I clear?
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #11 - Mar 5th, 2012 at 11:08pm
Print Post Print Post  
Yes, it is the Parent record but displayed in the different Layout (not the one with subform). And from that form the subrecord is created in the resultset using (command button) to be reparented to Parent record so that it shows up in the subform.
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #12 - Mar 6th, 2012 at 6:06pm
Print Post Print Post  
So long as the parent record is open, through any layouts, the @xResultSetReparent ( ) command seems to fail. However, when test is run to see if the parent record is locked, the results shows the record is not locked. I am lost...  Embarrassed

  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Needs help with xResultsetReparent ( ) command
Reply #13 - Mar 6th, 2012 at 6:42pm
Print Post Print Post  
Reparent requires that all of the child records in the result set be exclusively in that result set and no other. If some of the records are derived from an open subform, then some of the records are in another result set, the one for that subform. So if you are then adding to a set that already has some records, and these pre-existing records correspond to some on an open sub-form, some of your records are new and exclusive, but others are in a pre-existing second result set.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2483
Joined: Aug 20th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #14 - Mar 6th, 2012 at 6:55pm
Print Post Print Post  
Bharat_Naik wrote on Mar 6th, 2012 at 6:06pm:
So long as the parent record is open, through any layouts, the @xResultSetReparent ( ) command seems to fail. However, when test is run to see if the parent record is locked, the results shows the record is not locked. I am lost...  Embarrassed


Hello Bharat,

The records will not show as locked if they are open by the same client or if they are not the active record in another person's resultset. Mark is right that the XResultSetReparent command needs to have exclusive access to all the children records. It also needs exclusive access to the parent record, meaning that no other resultset can contain the parent or any of the child records(even if they are not the current record).

If you check @Error after the XResultSetReparent() call, it will return yes to indicate that it could not complete the reparenting procedure.

-Ray
  

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


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #15 - Mar 6th, 2012 at 7:07pm
Print Post Print Post  
In that case, what can I do, so that @XResultSetReparent ( ) commands works in the given circumstances. In other words, how do I give the exclusive access of Child records to the parent record?
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #16 - Mar 6th, 2012 at 8:25pm
Print Post Print Post  
Also, why @XResultSetReparent ( ) command will work (The same code) when activated from the form of different database?  I am just trying to understand the logic. In both the cases, the form with the subform is not open. Only the Resultset addresses the parent database and child database.
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Needs help with xResultsetReparent ( ) command
Reply #17 - Mar 6th, 2012 at 8:55pm
Print Post Print Post  
The answer has to do with natural linking. Natural linked records in Sesame, when not in a result set, store pointers to the records before and after them, and if they have children, they have a pointer to the first record in the child chain of records.

When they are in a result set, an array of pointers is declared. Each element in that array points at a single record. There is then a central pointer for the whole result set that indicates the current record. When that current record pointer advances through the array, if the old current record has child result sets, the records in those result sets are relinked to resolve their new order and status. They are then removed from the result set to be replaced by the child records of the new current parent.

If you reparent records that appear in more than one result set, and the parent record for either the SBasic bound result set, or the form's result set, causes a relinking, and that relinking does not correspond to the linking that either SBasic or the form is counting on, one or both are likely to become confused. Records could be orphaned, etc.

Records in a result set are not copies of the record, with separate natural linking information. So, I guess I would recommend that you take advantage of the "X" in "XResultSet" and do reparenting from some point other than one that contains the record you are affecting. This all a bit like trying to change the tires on a moving car from inside the car.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #18 - Mar 6th, 2012 at 9:26pm
Print Post Print Post  
Mark, thanks for explanation. What I could do is make one boolean field in subrecord and check it if it is made from one of the form of the same database. Process these subrecords, child records, for re-parenting from different database form such as Menu using command button, even better activate it from one of the forms that I work with frequently during the course of the day using @ClientLocalValue ( ) to limit frequent unnecessary processing. Any better solution?
  
Back to top
 
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Needs help with xResultsetReparent ( ) command
Reply #19 - Mar 6th, 2012 at 9:41pm
Print Post Print Post  
That sounds okay. You could work from the form you are on already, just make sure that it, nor its children are in the result sets you are reparenting. This is easy to accomplish in add mode, where your result set is entirely empty. Or, just as easily, from a form made just for the purpose of reparenting other records. I'd lean toward the latter, in that reparenting is a vey serious operation, and I wouldn't want to simply place it on a commonly used form.

  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #20 - Mar 6th, 2012 at 10:35pm
Print Post Print Post  
Thanks Mark and Ray. I will report after having successfully implemented. Now I have a little better understanding. Thanks again.  Smiley
  
Back to top
 
IP Logged
 
Bharat_Naik
Senior Member
Members
*****
Offline


Ever ready to learn and
share

Posts: 1202
Location: Chicago,  Illinois
Joined: Dec 16th, 2003
Re: Needs help with xResultsetReparent ( ) command
Reply #21 - Mar 7th, 2012 at 7:04am
Print Post Print Post  
Implemented the ReParent Routine from a form of other database and it works great. Also put certain error catching codes and safeguards.  The code is processed only if Flag with ClientLocalValue ( ) is created, thereby conserve resources.  It works along with the normal daily addition of records, so no other special  procedure needed to reparent the subrecord.  Special thanks to Ray and Mark for making the concept clear.
Following is the code:
Code
Select All
var vParentRSID as Int
var vChildRSID as Int
var vChart as String
var vChartString as String
var vRecordsFound as Int
var vFailureIndicator as Boolean = 0

var n as Int


// The Same code has been placed in DX2 of Physical File on Element Exit Event for New Records Only


If @ClientLocalValue ("ToBeReParented") = "Yes" then   //The value is set in Index or Recall DocManage to prevent Processing Unnecessary Processing code
	{

		vChildRSID = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Marker=" + 1)

			If vChildRSID > -1 then
				{
					vRecordsFound = @XResultSetTotal (vChildRSID)

					For n = 1 to vRecordsFound
						XResultSetCurrentPosition (vChildRSID, n)
						If vChartString = "" then
							{
								vChartString = @XResultSetValue (vChildRSID, "Chart")

							}
							Else
							{
								vChartString = vChartString + ";" + @XResultSetValue (vChildRSID, "Chart")

							}
					Next

					XResultSetClose (vChildRSID)

				}


		For n = 1 to @CountStringArray (vChartString)
			vChart = @AccessStringArray (vChartString, n)


				vParentRSID = @XResultSetSearch(@FN, "Index", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)

					If vParentRSID > -1 then
						{
							vRecordsFound = @XResultSetTotal (vParentRSID)

							If vRecordsFound = 1 then
								{
									vChildRSID = @XResultSetSearch(@FN, "Index!Documents", SEARCH_MODE_AND, SEARCH_SYNTAX_QA, "!Chart=" + vChart)

									If vChildRSID > -1 then
										{

							                                xResultSetSort (vChildRSID, "DateAdded:1")
											xResultSetReparent (vParentRSID, "DocumentSubForm", vChildRSID)
											If @Error then
												{
													WriteLN ("Reparent Failed, Close the Record for the Patient with " + vChart + " number in Index Database Forms")
													VFailureIndicator = 1
												}
												Else
												{
													XResultSetValue (vChildRSID, "Marker", 0)

												}



											xResultSetClose (vChildRSID)
										}

								}

								Else if vRecordsFound = 0 then
								{
									WriteLN ("Chart " + vChart + " Does not exist in INDEX Database!!! Please Correct it" )
									vFailureIndicator = 1
								}
								Else if vRecordsFound > 1 then
								{

									WriteLN ("Chart " + vChart + " has Multiple Entries in INDEX Database!!! Please Correct it" )
									vFailureIndicator = 1
								}

							XResultSetClose (vParentRSID)


						}
		Next

		If vFailureIndicator = 0 then
			{

				ClientLocalValue ("ToBeReParented", "")    // Reset it so, the program will not run next time unless Index or Recall form process some document
			}
	}
 

  
Back to top
 
IP Logged