Sidebar

Combodo

iTop Extensions

Hyperlinks configurator

m( m( m( Included in Professional product from 3.1.0 8-) 8-) 8-)

name:
Hyperlinks configurator
description:
Create custom hyperlinks on objects' details, by configuration
version:
1.1.3
release:
2023-07-13
code:
combodo-custom-hyperlinks
state:
stable
diffusion:
Client Store, iTop Hub
php-version-max:
PHP 8.1

Features

Allow to jump on other applications or execute actions on iTop object. The below actions are out of the box:

  • From a person, you can search them in LinkedIn
  • From a Location, you can search it in Google Maps
  • From a Ticket, you can add (or remove) yourself to the Ticket's contacts in one click
  • From a Audit Domain, Category and Rule, you can run the audit to test / check the results.

Those actions can be modified or removed and more actions can be configured without writing a single line of code:

  • Specify a label, tooltip and icon (one single language)
  • The action can be proposed on an subset of objects (production only for eg.)
  • The action can be proposed in the console and/or on the portal(s)
  • The action can be limited to users having a particular profile

Revision History

Version Release Date Comments
2023-07-13 1.1.3 * Add compatibility with iTop 3.0
* N°6004 - Add out-of-the box examples of hyperlinks
* N°1350 - Audit classes: add navigation to audit results
2021-10-14 1.1.2 - Added the ability to have a button calling a method (i.e. method://SomeMethod()) inside the portal.
- Actions calling a method can now also be displayed as “shortcut actions” (i.e. outside of the “Other actions” menu)
- Retrocompatibility with iTop 2.6.x
2021-05-10 1.1.0 Add iTop 3.0 compatibility
2020-11-08 1.0.4 New capability to call a method on the selected object via an Ajax call, with the URL scheme method://SomeMethod()
Label and tooltip are now treated as template strings (i.e. $this->att_code$ is supported)
Menus items declared on a class are now inherited on derived classes
Extended support for Font Awesome 5 “brand” icons (see the note about icons below).
2019-03-19 1.0.2 Add it on Portal objects with scope
Add “allowed_profiles” parameter
2019-03-15 1.0.1 Addition of the “tooltip” and “contexts” parameters
2019-02-07 1.0.0 First version

Limitations

  • Button labels cannot be localized (they are not dictionary entries)

Requirements

iTop 2.3.0 or newer

Buttons calling a method (scheme method://) are only supported on iTop 2.6 or newer.

Installation

Use the Standard installation process for this extension.

Configuration

For each “link” to be displayed, the following configuration parameters are available:

Parameter Mandatory? Meaning Example
label mandatory if no icon The label of the button/link Wikipedia
url mandatory The hyperlink to jump to https://www.wikipedia.org/wiki/$this->first_name$_$this->name$. Note: since 1.0.3 you can use the special syntax method://SomePublicMethod() to generate a menu item that will call the specified method of the object.
target optional where to display the url result _blank for a new window default, _top for the current window _blank
scope optional An OQL query to filter on which object to display this link SELECT Contact WHERE org_id = 2
icon optional A Font Awesome icon code. See the note about icons below. wikipedia
tooltip optional The label of a tooltip to display on the item. default: no tooltip Lookup $this->name$ in Wikipedia
contexts optional If specified, a comma separated list of portals in which to enabled this link. Use backoffice for the iTop console. If not specified, it's available in all contexts backoffice,itop-portal
allowed_profiles optional If specified, a comma separated list of iTop Profiles for which to enable this link. If not specified, all profiles are allowed. Support Agent,Configuration Manager
From version 1.1.3 onwards, this extension comes with the below default configuration
Configuration file
'combodo-custom-hyperlinks' => array (
   'hyperlinks' => array (
      'Person' => array (
         'linkedin_me' => array (
            'label' => 'Linkedin Me!',
            'url' => 'https://www.linkedin.com/search/results/all/?keywords=$this->friendlyname$',
            'scope' => 'SELECT Person',
            'icon' => 'fab fa-linkedin',
            'contexts' => 'backoffice',
         ),
      ),
      'Location' => array (
         'maps_me' => array (
            'label' => 'GoogleMaps Me!',
            'url' => 'https://www.google.com/maps/search/$this->address$+$this->postal_code$+$this->city$+$this->country$',
            'scope' => 'SELECT Location WHERE org_id_friendlyname=\'demo\'',
            'icon' => 'fas fa-globe',
            'contexts' => 'backoffice',
         ),
      ),
      'AuditDomain' => array(
         'UI:Menu:RunAudit' => array(
            'label' => 'Run the audit',
            'url' => 'audit.php?operation=audit&domain=$this->id$',
            'scope' => 'SELECT AuditDomain',
            'target' => '_top',
            'tooltip' => 'Run audit for this Domain',
            'icon' => 'fas fa-play-circle fa-lg',
            'contexts' => 'backoffice',
         ),
      ),
      'AuditCategory' => array(
          'UI:Menu:RunAudit' => array(
              'label' => 'Run the audit',
              'url' => 'audit.php?operation=audit&categories=$this->id$',
              'scope' => 'SELECT AuditCategory',
              'target' => '_top',
              'tooltip' => 'Run audit for this Category',
               'icon' => 'fas fa-play-circle fa-lg',
              'contexts' => 'backoffice',
           ),
       ),
      'AuditRule' => array(
          'UI:Menu:RunAudit' => array(
              'label' => 'Run the audit',
              'url' => 'audit.php?operation=audit&categories=$this->category_id$&rule=$this->id$',
              'scope' => 'SELECT AuditRule',
              'target' => '_top',
              'tooltip' => 'Run audit for this Rule',
              'icon' => 'fas fa-play-circle fa-lg',
              'contexts' => 'backoffice',
           ),
       ),
       'Ticket' => array (
          'UI:Menu:AddMeToContact' => array (
              'label' => 'Add me to contacts',
              'url' => 'method://AddCurrentUserToContacts()',
              'scope' => 'SELECT Ticket WHERE id NOT IN (SELECT Ticket AS U JOIN lnkContactToTicket AS L ON L.ticket_id=U.id WHERE L.contact_id=:current_contact_id)',
              'icon' => 'fas fa-user-plus',
              'contexts' => 'backoffice',
          ),
          'UI:Menu:RemoveMeFromContact' => array (
              'label' => 'Remove me from contacts',
              'url' => 'method://RemoveCurrentUserFromContacts()',
              'scope' => 'SELECT Ticket AS U JOIN lnkContactToTicket AS L ON L.ticket_id=U.id WHERE L.contact_id=:current_contact_id',
              'icon' => 'fas fa-user-minus',
              'contexts' => 'backoffice',
          ),
       ),
   ),
),
You can also display the hyperlink as a button (next to the “Other actions…” menu) by specifying in the configuration parameter shortcut_actions its UID (in the above LinkedIn example the UID is “linkedin_me”)
In that case, you must specify an tooltip entry, which will help the user to understand better the icon purpose.
When using the special syntax method://SomeMethod() for the url, the menu item will be a piece of Javascript that triggers an Ajax call during which the specified method is executed on the object. When this is done, the details of the object is displayed again (refreshed). If the object is to be modified by this method, then it's up to the method to call $this->DBWrite() to have the modified object persisted to the database. In order to display a message to the end-user, the method can call $this->SetSessionMessageFromInstance(...)
Starting with version 1.0.3, if the icon string contains spaces, it will be used as-is as the class to be applied to the <i> tag. This enables the support of FontAwesome 5 brand icons. For example when Font Awesome 4.7 is used (iTop up to version 2.7), the code for the LinkedIn icon is linkedin, when FontAwesome 5 is used (iTop version 3.0), the code is fab fa-linkedin.

Usage

Just click on the button(s) !  Hyperlinks configurator linkedin  Hyperlinks configurator Google  Hyperlinks configurator portal

Questions & Answers

Q: When I try to Add me to contacts on a ticket I get this error message:
The method 'AddCurrentUserToContacts' does not exist on the class 'UserRequest'. Check the configuration of the menu with UID = 'UI:Menu:AddMeToContacts'

Answer: You have 3 options:

  1. Upgrade your iTop to version 3.1
  2. Remove those hyperlinks configuration entries
  3. Customize your iTop, by adding those 2 methods on Tickets AddCurrentUserToContacts() and RemoveCurrentUserFromContacts()
Ticket
   public function AddCurrentUserToContacts()
   {
        $iPersonId = UserRights::GetContactId();
        if ($iPersonId > 0) {
            $oContactsSet = $this->Get('contacts_list');
            if (!in_array($iPersonId, $oContactsSet->GetColumnAsArray('contact_id'))) {
                $oLnk = MetaModel::NewObject('lnkContactToTicket');
                $oLnk->Set('contact_id', $iPersonId);
                $oLnk->Set('ticket_id', $this->GetKey());
                $oContactsSet->AddItem($oLnk);
                $this->Set('contacts_list', $oContactsSet);
                $this->DBUpdate();
            }
        }
        return true;
   }
   public function RemoveCurrentUserFromContacts()
   {
        $iPersonId = UserRights::GetContactId();
        if ($iPersonId > 0) {
            $oContactsSet = $this->Get('contacts_list');
            foreach ($oContactsSet as $oLnk) {
                if ($oLnk->Get('contact_id') == $iPersonId) {
                    $oContactsSet->RemoveItem($oLnk->GetKey());
                    $this->Set('contacts_list', $oContactsSet);
                    $this->DBUpdate();
                    return true;
                }
            }
        }
        return true;
   }

Q: Can I use this extension to propose a user action which would create or update objects on multiple classes at once?
A: Yes, this extension can be one part of the solution. In addition you will need to write you own extension to provide that complex action as a PHP method on the class on which the user will trigger the action.

An exemple a customer to whom you deliver services, is terminating its contract, as a result, you would like to close all the tickets open by its users, set all its contact status to inactive, disable all its user account, set all its CDMB owned CIs to obsolete and so on… For this you will need to write a PHP method for eg on the Organization class. That method will called by an action on the details of the Organization. So the User will trigger that Terminate customer action on the organization he wants to terminate.

class:Organization
public function TerminateCustomer()
{
   $iOrgID = $this->GetKey();
   // Desactivate Contacts
   $oSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT Contact WHERE org_id =$iOrgID"));
   while ($oContact = $oSet->Fetch())
   {
       $oContact->Set('status','inactive');
       $oContact->DBUpdate();
   }
   // Disable Users
   $oSet = new CMDBObjectSet(DBObjectSearch::FromOQL("SELECT User WHERE org_id =$iOrgID"));
   while ($oUser = $oSet->Fetch())
   {
       $oUser->Set('status','disabled');
       $oUser->DBUpdate(); 
   }
   // Auto-resolve UserRequests
   $oSet = new CMDBObjectSet(DBObjectSearch::FromOQL(
     "SELECT UserRequest WHERE org_id =$iOrgID AND status IN ('new','assigned','pending','approved')"
   ));
   while ($oUserRequest = $oSet->Fetch())
   {
       $oUserRequest->ApplyStimulus('ev_autoresolve');
       // No need to call DBUpdate(), it's done within ApplyStimulus 
   }
   // Other automations...
}
The caller of the method need to have write access on all updated classes: User, Contact, UserRequest, FunctionalCIs,…

Then add an entry in the Configuration File, to display that action to the users with enough rights to do it

config-itop.php
'combodo-custom-hyperlinks' => array (
    'hyperlinks' => array (  
        'Organization' => array (
                'terminate_customer' => array (
                      'label' => 'Terminate Customer',
                      'url' => 'method://TerminateCustomer()',
                      'scope' => 'SELECT Organization',
                      'allowed_profiles' => 'Administrator',
                      'icon' => 'fas fa-skull-crossbones',
                      'contexts' => 'backoffice',
                ),
        ),
    ),
),
extensions/combodo-custom-hyperlinks.txt · Last modified: 2024/02/12 11:11 (external edit)
Back to top
Contact us