Sidebar

Using iTop

Creating your iTop

iTop Customization

"How to" examples
DataModel

User Interface

Automation & Ticket management

Portal Customization

:: Version 3.2.0 ::

Add action on a list

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

learning:
Define an action to quickly bulk edit an n:n relationship
level:
Advanced
domains:
PHP, Navigation
methods:
EnumItems, GetObject, IsActionAllowed, FromOQL, AddCondition, GetFilter
min version:
2.3.0

Bulk edit remote objects

In this example we want to propose an action on a list of CIs linked to a Problem or a NormalChange, which would directly open a bulk modification screen limited to the Application Solutions linked to the Ticket. We don't want to propose this action elsewhere.

class AddModifyAllMenuPlugIn implements iPopupMenuExtension
{
   public static function EnumItems($iMenuId, $param) 
   {
      $aExtraMenus = array();
      if ($iMenuId ==  iPopupMenuExtension::MENU_OBJLIST_TOOLKIT && $param->GetFilter()->GetClass() === 'lnkFunctionalCIToTicket' ) {
         $oFilter = $param->GetFilter();
         $sClass = $oFilter->GetClass();
         $sOQL = $oFilter->ToOQL();
         if(str_contains($sOQL, "`Ticket`.`id` = :id")) {
            $oTicket = MetaModel::GetObject('Ticket',$oFilter->GetInternalParams()['id']);
            if(in_array(get_class($oTicket),['Problem','NormalChange'])) {
                if (UserRights::IsActionAllowed($sClass, UR_ACTION_BULK_MODIFY) != UR_ALLOWED_NO) {
                   $oApplicationQuery = DBSearch::FromOQL('SELECT ApplicationSolution');
                   $oApplicationQuery->AddCondition_ReferencedBy($param->GetFilter(), 'functionalci_id');
                   $aExtraMenus[] = new URLPopupMenuItem('ModifyAll::lnkFunctionalCIToTicket', 'Modify application solutions',
                      utils::GetAbsoluteUrlAppRoot()."pages/".cmdbAbstractObject::ComputeStandardUIPage($sClass)
                      ."?operation=select_for_modify_all&class=ApplicationSolution&filter=".urlencode('["'.$oApplicationQuery->ToOQL(true).'",{},[]]')
                   );
                }
            }
         }
      }
      return $aExtraMenus;
   }
}

You may want to bulk edit a set of attributes defined in an n:n relationship, without having to execute through the Run query menu a

SELECT lnkFunctionalCIToTicket WHERE ticket_id=:id

entering the id of the Ticket and then bulk modify the resulting links

If this is something you need to do often, you can add an action on the FunctionalCI tab when displayed within a Ticket to perform much more quickly this action. The code to use is very similar to the above code except the class returned in the URL and the filter

             $oLnkQuery = DBSearch::FromOQL('SELECT lnkFunctionalCIToTicket');
                   $oLnkQuery->AddCondition('ticket_id', $oFilter->GetInternalParams()['id']);
                   $aExtraMenus[] = new URLPopupMenuItem('ModifyAll::lnkFunctionalCIToTicket', 'Bulk modify the Links',
                      utils::GetAbsoluteUrlAppRoot()."pages/".cmdbAbstractObject::ComputeStandardUIPage($sClass)
                      ."?operation=select_for_modify_all&class=lnkFunctionalCIToTicket&filter=".urlencode('["'.$oLnkQuery->ToOQL(true).'",{},[]]')
                   );

Similar Tutorials
3_2_0/customization/bulk-edit-links.txt ยท Last modified: 2024/09/10 10:25 by 127.0.0.1
Back to top
Contact us