Search code examples
perlotrs

Global symbol "%CustomerCompanyName" requires explicit package name


I am not a Perl expert, but I'm trying to edit the OTRS software to add support for CustomerCompanyName column as follows, but I am getting the error

Global symbol "%CustomerCompanyName" requires explicit package name at /opt/otrs//Kernel/Output/HTML/Dashboard/TicketGeneric.pm line 1516.

I have googoled a bit, and find out that's a problem with "my" and variable declaration, but after a while, I have not find out yet what I am doing wrong.

Change is applied by adding at this line: https://github.com/OTRS/otrs/blob/1e908159a5dbdcfb94cc35d13bf15b04ac3e6a24/Kernel/Output/HTML/Dashboard/TicketGeneric.pm#L1510

        elsif ( $Column eq 'CustomerCompanyName' ) {

            # get customer name
            my $CustomerCompanyName;
            if ( $Ticket{CustomerID} ) {
                $CustomerCompanyName = $Kernel::OM->Get('Kernel::System::CustomerCompany')->CustomerCompanyGet(
                    CustomerID => $Ticket{CustomerID},
                );
                $CustomerCompanyName = $CustomerCompanyName{'CustomerCompanyName'};
            }
            $DataValue = $CustomerCompanyName;
        }

Solution

  • The problem you are seeing is caused by the line:

    $CustomerCompanyName = $CustomerCompanyName{'CustomerCompanyName'};
    

    and it looks like you meant to write:

    $CustomerCompanyName = $CustomerCompanyName->{'CustomerCompanyName'};
    

    (notice the dereferencing arrow).

    $CustomerCompanyName{'CustomerCompanyName'} is a key in a hash %CustomerCompanyName, which is different than $CustomerCompanyName, the scalar you declared and then gave a value (presumably a hash ref).