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:
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
}
}