Sidebar

Using iTop

Creating your iTop

iTop Customization

"How to" examples
DataModel

User Interface

Automation & Ticket management

Portal Customization

:: Version 3.1.0 ::

Add a TagSet in PHP

Prerequisite: You must be familiar with the Syntax used in Tutorials and have already created an extension.
We also assume that you are familiar with dashboard design within iTop and OQL.

learning:
Within a PHP method, adding a value to a TagSet
level:
Medium
domains:
PHP, TagSet, Attribute
methods:
PrefillTransitionForm, Set, Get, GetTagFromLabel, Warning
min version:
2.6.0

If you want to add within a method a particular value to a TagSet attribute.
In the below non-standard example, we have a class Bug,

  • with a String field version ( an external field inherit from the Sprint during which that Bug will be worked on.)
  • and a TagSet versions which corresponds to the versions of the products in which that Bug was fixed
  • by default, on bug resolution, we want to be sure that at least the “version” of the Sprint is part of the “fixed in versions”
class:Bug
public function PrefillTransitionForm(&$aContextParam)
{
    switch ($aContextParam['stimulus']) {
 [...]
        case 'ev_resolve':
            try {   // Get the version which is a string
                    $sVersion = $this->Get('version');
                    // Get the versions in which the Bug is supposed to be fixed (it's an ormTagSet)
                    $oVersions = $this->Get('versions');
                    // Get the TagSetFieldData code, corresponding to a given label (here my version)
                    $Tag = $oVersions->GetTagFromLabel($sVersion);
                    // Add this code to the TagSet if not already in.
                    $oVersions->Add($Tag);
                    // Set the result in the object
                    $this->Set('versions', $oVersions);
            } catch (Exception $e) {
                // An exception is raised by GetTagFromLabel(), if the label is not a valid one for this TagSet
                // You may log it or ignore the issue
                IssueLog::Warning($e);
            }
            break;
 [...]
    }
}

You can get an exception if the label is not an existing value in your tagset: CoreUnexpectedValue: 4.0.0 is not defined as a valid tag for Bug:versions in…


Similar Tutorials
3_1_0/customization/add-value-to-tagset.txt · Last modified: 2023/07/21 10:19 (external edit)
Back to top
Contact us