Using iTop

Creating your iTop

iTop Customization

"How to" examples

User Interface

Automation & Ticket management

Portal Customization

:: Version 3.2.0 ::

Copy linkedset with object copier

Prerequisite: You must be familiar with the Syntax used in Tutorials and have already created an extension.

Create a method used by Object Copier
min version:

In this tutorial, we will see how we can enrich the extension User actions configurator, to copy relationships.
Example: When creating a Ticket from a FunctionalCI, we want to retrieve contacts linked to the Functional CI and link them automatically to the Ticket.

public function CopyContactsFromFunctionalCI($oSource)
   // This method is supposed to be called from a FunctionalCI.
   $sSourceClass = get_class($oSource);
   if ($sSourceClass != 'FunctionalCI')
        throw new Exception("Wrong source class '$sSourceClass' : 
        CopyContactsFromFunctionalCI method should be called by a user action on a FunctionalCI!");
   // This method is called twice: 
   //   when creation form is displayed: '????'
   //   and when it is saved : 'apply_new' 
   // Copy the links only in one case, to avoid links duplication
   $sOperation= utils::ReadPostedParam('operation');
   if ($sOperation == 'apply_new')
   // Get the list of related objects - in this case, the OQL is not needed but it works
   $oSetSrc = new CMDBObjectSet(DBObjectSearch::FromOQL("
        SELECT Contact AS c
        JOIN lnkContactToFunctionalCI AS l1 ON l1.contact_id =
        WHERE l.functionalci_id = :id"), array(), array('id'=>$oSource->GetKey()));
   // A simpler solution is to use: $oSetSrc = $oSource->Get('contacts_list');
   $oSetDst = $this->Get('contacts_list');
   while ($oSrc = $oSetSrc->Fetch())
        $oLnkDst = MetaModel::NewObject('lnkContactToTicket');
        $oLnkDst->Set('contact_id', $oSrc->GetKey());
    $this->Set('contacts_list', $oSetDst);
3_2_0/customization/object-copier-linkedset.txt ยท Last modified: 2024/06/20 17:28 (external edit)
Back to top
Contact us