You are browsing the documentation for iTop 3.0 which is not the current version.

Consider browsing to iTop 3.1 documentation

Add a value in a TagSet

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
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 an ExternalField version which is defined by the Spring containing that Bug
  • 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 Spring 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…

3_0_0/customization/add-value-to-tagset.txt · Last modified: 2022/05/04 19:25 (external edit)
Back to top
Contact us