Menu

Undefined index error - please help!

Mojo
2011-04-04
2012-12-19
  • Mojo

    Mojo - 2011-04-04

    Hi everyone,

    I added some extra fields to the existing Network Device model, maintenance_cost and updated the DB schema for this field.  Below is the attribute I added:

    MetaModel::Init_AddAttribute(new AttributeString("maintenance_cost", array("label"=>"Maintenance Cost", "description"=>"Maintenance Cost", "allowed_values"=>null, "sql"=>"maintenance_cost", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
    

    I then imported devices and values inserted into this field, but when ever I click on the device to show the details I get the following error:

    Notice: Undefined index: maintenance cost in C:\wamp\www\itop1.0\core\metamodel.class.php on line 593

    Fatal error: Call to a member function GetLabel() on a non-object in C:\wamp\www\itop1.0\core\cmdbchangeop.class.inc.php on line 216

    What am I doing wrong?  Any help with this would be greatly appreciated :)

     
  • Romain Quetiez

    Romain Quetiez - 2011-04-14

    Hi,

    I have looked into the code. This symptom could be encountered if the declaration of the new attribute is made out of the Init() function of the class.

    Please, make sure that any new attribute be declared in the same function as the other ones:

    class Server extends InfrastructureCI
    {
        public static function [b]Init()[/b]
        {
            $aParams = array
            (
                "category" => "bizmodel,searchable,configmgmt",
                "key_type" => "autoincrement",
                "name_attcode" => "name",
                "state_attcode" => "",
                "reconc_keys" => array("name","org_id","owner_name","location_id","location_name"),
                "db_table" => "server",
                "db_key_field" => "id",
                "db_finalclass_field" => "",
                "icon" => "../modules/itop-config-mgmt-1.0.0/images/server.png",
            );
            MetaModel::Init_Params($aParams);
            MetaModel::Init_InheritAttributes();
            MetaModel::Init_AddAttribute(new AttributeString("[b]my_custom_attribute[/b]", array("allowed_values"=>null, "sql"=>"my_custom_attribute", "default_value"=>"", "is_null_allowed"=>true, "depends_on"=>array())));
    ...
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.