Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (Flatly)
  • No Skin
Collapse
Brand Logo

NetXMS Forum

  1. Home
  2. Support
  3. java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttri

java.lang.String cannot be cast to org.netxms.client.objects.configs.CustomAttri

Scheduled Pinned Locked Moved Support
5 Posts 2 Posters 58.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B
    B
    BigBlue
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • V
      V
      Victor Kirhenshtein
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      • B
        B
        BigBlue
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • V
          V
          Victor Kirhenshtein
          wrote on last edited by
          #4

          Are you sure that findObjectByName didn't fail? Try to check return value for None before using it for getObjectId.

          Best regards,
          Victor

          1 Reply Last reply
          0
          • B
            B
            BigBlue
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0

            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
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            Powered by NodeBB Contributors
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups