NetXMS Support Forum

English Support => General Support => Topic started by: BigBlue on February 27, 2020, 05:16:50 PM

Title: java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttri
Post by: BigBlue on February 27, 2020, 05:16:50 PM
Hello,

I updated my netxms and nxshell version (2.2.15 => 3.1)

An attribute creation script doesn't work anymore.
Can you help it?

import csv, sys
from java.util import HashMap
...
...
        MAT = s.findObjectByName(MATname)
        if MAT :
            MATId = MAT.getObjectId()
            md = NXCObjectModificationData(MATId)
            MODIF = HashMap()
            MODIF.put("UR1location", Location)
            md.setCustomAttributes(MODIF)
            session.modifyObject(md)   
            w.writerow([
                MAT.getObjectId(),
                MAT.getObjectName(),
                MAT.getCustomAttributes(),
                ])


I'm getting the next error:

Traceback (most recent call last):
  File "/data/infra/scripts/NetXMS/Custom-Attributes_UR1location.py", line 27, in <module>
    session.modifyObject(md)
at org.netxms.client.NXCSession.modifyObject(NXCSession.java:5152)
at org.netxms.client.NXCSession.modifyObject(NXCSession.java:5691)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
java.lang.ClassCastException: java.lang.ClassCastException: java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttribute



Thank's
Title: Re: java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttri
Post by: Victor Kirhenshtein on February 27, 2020, 05:54:30 PM
Hi,

setCustomAttributes methos now expects Map<String, CustomAttribute> instead of Map<String, String>. Try to replace line

MODIF.put("UR1location", Location)

with

MODIF.put("UR1location", CustomAttribute(Location, 0, 0))

Best regards,
Victor
Title: Re: java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttri
Post by: BigBlue on February 28, 2020, 11:15:12 AM
It's working great!
Thank a lot.

I have other problems when creating maps...

Seed = s.findObjectByName("NameOfMySeed")
SeedId = Seed.getObjectId()

NetworkMaps = s.findObjectByName("Network Maps")
NetworkMapsId = NetworkMaps.getObjectId()

SnmpLocationKO = s.findObjectByName("Snmp Location KO")
SnmpLocationKOId = SnmpLocationKO.getObjectId()


I have this error:
Traceback (most recent call last):
  File "/data/infra/scripts/NetXMS/Creation-de-map_ALL.py", line 27, in <module>
    SnmpLocationKOId = SnmpLocationKO.getObjectId()
AttributeError: 'NoneType' object has no attribute 'getObjectId'


Can you help me again?

Thank you
BB
Title: Re: java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttri
Post by: Victor Kirhenshtein on February 28, 2020, 11:46:05 AM
Are you sure that findObjectByName didn't fail? Try to check return value for None before using it for getObjectId.

Best regards,
Victor
Title: Re: java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttri
Post by: BigBlue on February 28, 2020, 01:44:48 PM
Sorry, I'm really a newbie (I think you can tell), I'm taking over someone's job...

The "Snmp Location KO" card just didn't exist.
After create it, it's ok.

Many thanks.

Best regards,
BB