KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Finding all relations that include deletion control
PRODUCT: 4D | VERSION: 18 | PLATFORM: Mac & Win
Published On: December 28, 2020

Here is some sample code that can be used to parse a Structure XML File to find out which relationships within the structure where deletion control is set to "Delete related many"

Before running the sample code, you should first create a structure XML file by exporting the structure to XML from the File -> Export menu. Then, select that XML file while running this code. After the code finishes executing the results will be in the clipboard, simply paste the results into a new document.

Here is the code:

C_TEXT($new_xml;$xml_Child_Ref;$xml_source;$childName;$childValue;$next_XML_Ref)
C_TEXT($siblingElemName;$siblingElemValue;$attribName;$attribValue;$new_var)
C_TEXT($appendedRef)
C_LONGINT($count)

$new_xml:=DOM Create XML Ref("root")
$xml_source:=DOM Parse XML source("")
$xml_Child_Ref:=DOM Get first child XML element($xml_source;$childName;$childValue)
If ($childName="Schema")
  // ok
  $next_XML_Ref:=$xml_Child_Ref
  While (OK=1)
    $next_XML_Ref:=DOM Get next sibling XML element($next_XML_Ref\
      $siblingElemName;$siblingElemValue)
    If ($siblingElemName="relation")
        $count:=DOM Count XML attributes($next_XML_Ref)
        C_LONGINT($i;$end)
        $end:=$count
        For ($i;1;$end)
          DOM GET XML ATTRIBUTE BY INDEX($next_XML_Ref;$i;$attribName;$attribValue)
          If ($attribName="integrity")
             If ($attribValue="delete")
                $appendedRef:=DOM Append XML element($new_xml;$next_XML_Ref)
            End if
          End if
        End for
    End if
  End while
End if

DOM EXPORT TO VAR($new_xml;$new_var)
SET TEXT TO PASTEBOARD($new_var)

DOM CLOSE XML($new_var)
DOM CLOSE XML($xml_source)