Come aggiornare record duplicati in modo che corrispondano al record principale

Il seguente esempio di frammento di codice verifica se il record (entità) dispone di duplicati (elementi secondari). Se sì, l'hook modifica ognuno dei duplicati con nome azione dupone e imposta il campo "action_info" affinché indichi che il record originale (principale) è stato sottoposto a verifica.

Nota: l'utente sincronizza i record duplicati con quello originale utilizzando un hook Action Notification. Un hook Action Notification viene generato dopo che è stato eseguito il commit di un record sul database con esito positivo. È possibile utilizzare un hook Action Commit invece di un hook Action Notification. Tuttavia, utilizzare un hook Action Commit comporta un rischio: se sul database viene eseguito il commit dei record secondari, ma non del record principale, i record dell'utente non saranno sincronizzati. Inoltre, è possibile utilizzare azioni nidificate. Consultare "Controllo accesso e azioni" e Azioni nidificate.

VBScript

Dim status
Dim session    ' The current Session object
Dim parent_id    ' The current Entity's display name (ID string)
Dim dups  ' Array of all direct duplicates of this Entity
Dim dupvar    ' Variant containing a Link to a duplicate
Dim dupobj  ' The same Link, but as an Object rather than a Variant
Dim entity        ' The Entity extracted from the Link

If (HasDuplicates()) Then 
   Set session = GetSession 
   dups = GetDuplicates 
   parent_id = GetDisplayName 
   for each dupvar in dups 
      ' You could check these various functions for failures and 
      ' then report any failures to the user (for example, using
      ' MsgBox). 
      ' Failures are unlikely, but possible--for example, someone 
      ' could concurrently "unmark" an entity as a duplicate. 
      Set dupobj = dupvar 
      Set entity = dupobj.GetChildEntity 
      session.EditEntity entity, "dupdone" 
      SetFieldValue "action_info", _ 
            "Original " & parent_id & " is tested" 
      ' commit the record to the database if validation returns no
      ' errors

      status = entity.Validate 

     if status = "" then

         entity.Commit 
      else

          entity.Revert  

       End If
   Next 
End If 

Perl

my($session);    # The current Session object

my($links); # The reference to the links collection object

my($link);

my($cnt);

my($itm);

my($childID);



if ($entity->HasDuplicates()) {

    $session=$entity->GetSession();

    $links = $entity->GetDuplicates();

   $session->OutputDebugString("links is " . $links . "(" . ref ($links) . 
")\n" );

   $cnt = $links->Count();

   $session->OutputDebugString("count is " . $cnt . "(" . ref ($cnt) . 
")\nchildren:\n" );

   for ($i = 0; $i<$cnt; $i++) {

     $itm = $links->Item($i);

    $session->OutputDebugString("Item is " . $itm . "(" . ref ($itm) . ")\n";

     $childID = $itm->GetChildEntityId();

     $session->OutputDebugString($childID . "\n" );

     }

    $session->OutputDebugString("done");

   }

else {

} 


Feedback