java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttri
-
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.CustomAttributeThank's
-
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 -
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 -
Are you sure that findObjectByName didn't fail? Try to check return value for None before using it for getObjectId.
Best regards,
Victor -
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login