[SOLVED] ConfigItemID as Text not the number

Moderator: crythias

Post Reply
licorit
Znuny newbie
Posts: 44
Joined: 16 Jul 2013, 08:56
Znuny Version: 3.2.9
Real Name: Sebastian
Company: Licor
Location: Frankfurt/Main

[SOLVED] ConfigItemID as Text not the number

Post by licorit »

Hi i already posted in the german forum but there`s nobody who can help so I try it here.

I just did set up a dropdown menu for different departments when you create a computer CI.
CMDB2.jpg
This departemnt I want to see in the CMDB Overview as a column.

I got the column but it gets filled with the ConfigItemID instead of the text.
CMDB.jpg
Any ideas how I get to see the departments ?
You do not have the required permissions to view the files attached to this post.
Last edited by licorit on 09 Jan 2014, 14:48, edited 1 time in total.
OTRS 3.2.9 auf Ubuntu 12.4
Wolfgangf
Znuny ninja
Posts: 1029
Joined: 13 Apr 2009, 12:26
Znuny Version: 6.0.13
Real Name: Wolfgang Fürtbauer
Company: PBS Logitek GmbH
Location: Pinsdorf

Re: ConfigItemID as Text not the number

Post by Wolfgangf »

did you change code for adding this new column?
in gerneral you have to make general_catalog lookup to get the text for the ID
for example

Code: Select all

 #
            # check if Attribut is a GeneralCatalog Lookup item
            #
            my $ClassItemRef = $Self->{GeneralCatalogObject}->ItemGet(
                        Class => 'ITSM::ConfigItem::Class',
                        Name  => $VersionRef->{Class},
                    ) || 0;

            my $XMLDefinition = $Self->{ConfigItemObject}->DefinitionGet(
                        ClassID =>  $ClassItemRef->{ItemID},
                    );
             if ( !$XMLDefinition->{DefinitionID} ) {
                        $Self->{LogObject}->Log(
                            Priority => 'error',
                            Message  => "No Definition definied for class $VersionRef->{Class}!",
                        );
            }
Produktiv:
OTRS 6.0.13/ ITSM 6.0.13
OS: SUSE Linux (SLES 12, Leap), MySql 5.5.x, 5.6.x
Windows 2012 AD Integration (agents and customers), Nagios integration (incidents, CMDB), Survey, TimeAccounting
licorit
Znuny newbie
Posts: 44
Joined: 16 Jul 2013, 08:56
Znuny Version: 3.2.9
Real Name: Sebastian
Company: Licor
Location: Frankfurt/Main

Re: ConfigItemID as Text not the number

Post by licorit »

Hi Wolfgang,

first thanks for the quick response.

Yes actually i did change some code in the ITSMConfigItemOverviewSmall.pm

Code: Select all

# get config item data
                    my $ConfigItem = $Self->{ConfigItemObject}->VersionGet(
                        ConfigItemID => $ConfigItemID,
                        XMLDataGet   => 1,
                    );

          $ConfigItem -> {Abteilung} = $ConfigItem -> {'XMLData'}[1] -> {'Version'}[1] -> {'Abteilung'}[1] -> {'Content'};
So can i add this code piece from you in the ITSMConfigItemOverviewSmall.pm or somewhere else?

Im not a programmer so it would be nice if you could help me.
OTRS 3.2.9 auf Ubuntu 12.4
licorit
Znuny newbie
Posts: 44
Joined: 16 Jul 2013, 08:56
Znuny Version: 3.2.9
Real Name: Sebastian
Company: Licor
Location: Frankfurt/Main

Re: ConfigItemID as Text not the number

Post by licorit »

Push push.

Sorry guys but I still need some help.

Im trying to understand the code from Wolfgang but
my perl skills aren`t good enough.

Tried several things with that code and tried to understand it,
but i dont get it.

Nobody who could help me writing this right?
OTRS 3.2.9 auf Ubuntu 12.4
Wolfgangf
Znuny ninja
Posts: 1029
Joined: 13 Apr 2009, 12:26
Znuny Version: 6.0.13
Real Name: Wolfgang Fürtbauer
Company: PBS Logitek GmbH
Location: Pinsdorf

Re: ConfigItemID as Text not the number

Post by Wolfgangf »

Sorry, i try to explain again
you want to get the text displayed - not the id, correct?
the field you want to display is defined in the general catalog, correct?

as the field you want to display is a general catalog field, you need to get the description "abteilung bla boa" from the general catalog

so what I did with this code is
- check if the field is a general catalog field
- if yes: get the description for the given id

Code: Select all

 
            # create GeneralCatalogObject
            $Self->{GeneralCatalogObject} ||= Kernel::System::GeneralCatalog->new( %{$Self} );

            #
            # check if Attribut is a GeneralCatalog Lookup item
            #
            # get the class reference
            my $ClassItemRef = $Self->{GeneralCatalogObject}->ItemGet(
                        Class => 'ITSM::ConfigItem::Class',
                        Name  => $VersionRef->{Class},
                    ) || 0;

            # get the definition for the class and raise error if not found
            #
            my $XMLDefinition = $Self->{ConfigItemObject}->DefinitionGet(
                        ClassID =>  $ClassItemRef->{ItemID},
                    );
             if ( !$XMLDefinition->{DefinitionID} ) {
                        $Self->{LogObject}->Log(
                            Priority => 'error',
                            Message  => "No Definition definied for class $VersionRef->{Class}!",
                        );
            }

            # find the field in the class definition and retrieve the text from GeneralCatalog  into $Value
           #
            for my $i (0 .. $#{$XMLDefinition->{'DefinitionRef'}}) {
                if ($XMLDefinition->{'DefinitionRef'}[$i]->{Key} eq $ConfigItemKey) {
                    if (($XMLDefinition->{'DefinitionRef'}[$i]->{Input}->{Type}) eq 'GeneralCatalog') {
                        my $ItemValue = $Self->{GeneralCatalogObject}->ItemGet(
                            ItemID => $Value,);
                        $Value = $ItemValue->{Name};
                        ## 
                        ## now $Value holds "Abteilung boa, bla, bla" instead of 152
                        last;
                    }
                }
            }

            #
            # EO
            # check if Attribut is a GeneralCatalog Lookup item
            #
Produktiv:
OTRS 6.0.13/ ITSM 6.0.13
OS: SUSE Linux (SLES 12, Leap), MySql 5.5.x, 5.6.x
Windows 2012 AD Integration (agents and customers), Nagios integration (incidents, CMDB), Survey, TimeAccounting
licorit
Znuny newbie
Posts: 44
Joined: 16 Jul 2013, 08:56
Znuny Version: 3.2.9
Real Name: Sebastian
Company: Licor
Location: Frankfurt/Main

Re: ConfigItemID as Text not the number

Post by licorit »

Thanks again Wolfgang.

Alright I tried to understand and I know that my perl/otrs skills arent good enough to exactly understand.

The tricky part for me is that i already got the XML Value and somehow your code makes sense to me but i don know how
to use the existing XML Value to look in der Generalcatalog... so i just posted the code i have now.

It doesnt know what $ConfigItemkey and $Value is... just says a explicit package name is required....

The code piece is from the ITSMConfigItemOverviewSmall.pm
hope thats the place where to put it.

Does anybody know where I could learn some perl skills just beloging to OTRS?

Would like to understand more the variables/structures etc. and how OTRS is programmed.

If its too much than it is ok, dont want to bother you with this. Here my code at the moment:

Code: Select all

# show config items if there are some
    if (@ConfigItemIDs) {

        # to store all data /[b] is it right to declare the variables from your codepiece here???[/b]
        my %Data;
        my %ClassItemRef;
        my %VersionRef;
        my %Value;
        my %ConfigItemKey;
        my %XMLDefinition;

        ConfigItemID:
        for my $ConfigItemID (@ConfigItemIDs) {
            $Counter++;
            if (
                $Counter >= $Param{StartHit}
                && $Counter < ( $Param{PageShown} + $Param{StartHit} )
                )
            {

                # check for access rights
                my $HasAccess = $Self->{ConfigItemObject}->Permission(
                    Scope  => 'Item',
                    ItemID => $ConfigItemID,
                    UserID => $Self->{UserID},
                    Type   => $Self->{Config}->{Permission},
                );

                next ConfigItemID if !$HasAccess;

                # get config item data
                my $ConfigItem = $Self->{ConfigItemObject}->VersionGet(
                    ConfigItemID => $ConfigItemID,
                    XMLDataGet   => 1,
                );
               [b] # Getting the Owner Infos as XML [/b]
                $ConfigItem -> {Owner} = $ConfigItem -> {'XMLData'}[1] -> {'Version'}[1] -> {'Owner'}[1] -> {'Content'};
               [b] # Getting the Abteilung Infos as XML[/b]
                $ConfigItem -> {Abteilung} = $ConfigItem -> {'XMLData'}[1] -> {'Version'}[1] -> {'Abteilung'}[1] -> {'Content'};
                                       
                next ConfigItemID if !$ConfigItem;
                
                 # create GeneralCatalogObject/[b] Is this necessary, what does this do???[/b]
            $Self->{GeneralCatalogObject} ||= Kernel::System::GeneralCatalog->new( %{$Self} );

            # check if Attribut is a GeneralCatalog Lookup item,[b] just filled in the Class and the ConfigItem [/b]
            
            # get the class reference
            my $ClassItemRef = $Self->{GeneralCatalogObject}->ItemGet(
                       Class => 'ITSM::ConfigItem::Computer::Abteilung',
                      Name  => $ConfigItem->{Abteilung},
                 ) || 0;

            # get the definition for the class and raise error if not found,[b] dont know which info is needed here because i already got the XML Value above...[/b]
            
            my $XMLDefinition = $Self->{ConfigItemObject}->DefinitionGet(
                        ClassID =>  $ClassItemRef->{ItemID},
                   );
            if ( !$XMLDefinition->{DefinitionID} ) {
                        $Self->{LogObject}->Log(
                            Priority => 'error',
                            Message  => "No Definition definied for class $ConfigItem->{Abteilung}!",
                        );
            }

            # find the field in the class definition and retrieve the text from GeneralCatalog  into $Value, [b]makes sense but i dont know which data needs to be filled in[/b]
           
            for my $i (0 .. $#{$XMLDefinition->{'DefinitionRef'}}) {
               if ($XMLDefinition->{'DefinitionRef'}[$i]->{Key} eq $ConfigItemKey) {
                    if (($XMLDefinition->{'DefinitionRef'}[$i]->{Input}->{Type}) eq 'GeneralCatalog') {
                        my $ItemValue = $Self->{GeneralCatalogObject}->ItemGet(
                            ItemID => $Value,);
                        $Value = $ItemValue->{Name};
                       
                        ## now $Value holds "Abteilung boa, bla, bla" instead of 152,[b] okay how do i get %Value in the CMDB Overview? in the next part it is stored as %Data [/b]                   
                         last;
                   }
                }
            }

            #
            # EO
            # check if Attribut is a GeneralCatalog Lookup item
            
OTRS 3.2.9 auf Ubuntu 12.4
PaoloCeccacci
Znuny newbie
Posts: 12
Joined: 03 Dec 2012, 19:09
Znuny Version: 3.1.11
Real Name: Paolo Ceccacci
Company: Puntosys

Re: ConfigItemID as Text not the number

Post by PaoloCeccacci »

I had the same problem and needed to extrapolate some infos from General Catalog.
Let's say you have your personal class definition :

Code: Select all

{ 
        Key => 'MyType', 
        Name => 'MyType', 
        Searchable => 1, 
        Input => { 
            Type => 'GeneralCatalog', 
            Class => 'ITSM::ConfigItem::MyClass::MyType', 
            Translation => 1, 
        }, 
    },
Now you have different elements in the "ITSM::ConfigItem::MyClass::MyType" and you want the corrispetive value for each item shown.

So in ITSMConfigItemOverviewSmall.pm I have:

Code: Select all

my $ConfigItem = $Self->{ConfigItemObject}->VersionGet(
                    ConfigItemID => $ConfigItemID,
                    XMLDataGet   => 1,
                );
				#Get the General Catalog
				my $ValueID=$ConfigItem -> {'XMLData'}[1] -> {'Version'}[1] -> {'MyType'}[1] -> {'Content'};
				# create GeneralCatalogObject
				$Self->{GeneralCatalogObject} ||= Kernel::System::GeneralCatalog->new( %{$Self} );
				my $ClassItemRef = $Self->{GeneralCatalogObject}->ItemGet(
						Class => 'ITSM::ConfigItem::MyClass::MyType',
						ItemID => $ValueID ,
                    );

				
				$ConfigItem -> {Type} = $ClassItemRef -> {Name};
Since I got the ValueID directly from XMLdata I can use this value to sharply identify the data in the GeneralCatalogObject by passing the ValueID as ItemID to it!
No need to use recursive routines.
licorit
Znuny newbie
Posts: 44
Joined: 16 Jul 2013, 08:56
Znuny Version: 3.2.9
Real Name: Sebastian
Company: Licor
Location: Frankfurt/Main

Re: ConfigItemID as Text not the number

Post by licorit »

First thanks for your answer.

I used your code and changed it, but it doesnt work...im still getting the numbers instead of the real value.

Here what i did change:

Code: Select all

             # get config item data
                my $ConfigItem = $Self->{ConfigItemObject}->VersionGet(
                    ConfigItemID => $ConfigItemID,
                    XMLDataGet   => 1,
                );
                # Getting the Owner Infos as XML
                $ConfigItem -> {Owner} = $ConfigItem -> {'XMLData'}[1] -> {'Version'}[1] -> {'Owner'}[1] -> {'Content'};
                # Getting the Abteilung Infos as XML
                $ConfigItem -> {Abteilung} = $ConfigItem -> {'XMLData'}[1] -> {'Version'}[1] -> {'Abteilung'}[1] -> {'Content'};
                
                             
                # create GeneralCatalogObject
                $Self->{GeneralCatalogObject} ||= Kernel::System::GeneralCatalog->new( %{$Self} );
                my $ClassItemRef = $Self->{GeneralCatalogObject}->ItemGet(
                      Class => 'ITSM::ConfigItem::Computer::Abteilung',
                      ItemID => $ValueID ,
                        );

                
                $ConfigItem -> {Type} = $ClassItemRef -> {Name};
         
                next ConfigItemID if !$ConfigItem;
   
Im fine with the fact that i wont get it to show the real value...

anyway if you know whats wrong just let me know...

edit: the $ValueID is declared a few lines above as my $ValueID= ' ';
OTRS 3.2.9 auf Ubuntu 12.4
licorit
Znuny newbie
Posts: 44
Joined: 16 Jul 2013, 08:56
Znuny Version: 3.2.9
Real Name: Sebastian
Company: Licor
Location: Frankfurt/Main

Re: ConfigItemID as Text not the number

Post by licorit »

YES IT WORKS!!!!

Made some mistakes in my code.

BUT NOW IT WORKS. YEAH. IM HAPPY. MADE MY DAY

THANK YOU VERY MUCH PAOLO :) :) :)
OTRS 3.2.9 auf Ubuntu 12.4
Post Reply