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. Scripting problem with global variables in version 2.0-M2

Scripting problem with global variables in version 2.0-M2

Scheduled Pinned Locked Moved Support
3 Posts 2 Posters 11.4k 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.
  • D
    D
    DrCamel
    wrote on last edited by
    #1

    First, I just want to say what an excellent product NetXMS is, thanks to everyone involved in making it what it is today.

    Now on to the issue I am experiencing, I am having a problem with scripting in that global variables do not appear to be working correctly (or I am misunderstanding how to use them, which is possibly more likely).

    I am defining a global variable in the following way:-

    global GlobalStringConstant = "String Value";
    

    However when I try to reference the global variable in functions, all I get is a NULL object.

    To test this I created a script in the script library called "TestScript" with the following code:-

    global GlobalStringConstant = "String Value";
    
    sub main() {
    	typeofValue = typeof(GlobalStringConstant);
    	println "Type:-";
    	println typeofValue;
    
    	println "Value:-";
    	println GlobalStringConstant;
    }
    

    Then in the server console, when I issue the command "exec TestScript", I get the following output:-

    Type:-
    null
    Value:-
    
    
    INFO: Script finished with rc=0
    

    Where I was expecting the output:-

    Type:-
    string
    String Value
    INFO: Script finished with rc=0
    

    I am running the current development version 2.0-M2 with the 64bit binaries running on a Windows Server 2008 R2 virtual machine which is connected to a Microsoft SQL Server 2008 R2 backend database.

    Any assistance anyone can offer would be very much appreciated.

    Thanks!

    Simon

    1 Reply Last reply
    0
    • T
      T
      tomaskir
      wrote on last edited by
      #2

      In your example

      global GlobalStringConstant = "String Value";
      

      Is never executed

      Please read this article:
      https://wiki.netxms.org/wiki/UM:NetXMS_Scripting_Language_(NXSL)#Script_entry_point

      You implicit main is never executed, since you have an explicit main.
      Therefore, the variable "GlobalStringConstant" is never initialized.

      1 Reply Last reply
      0
      • D
        D
        DrCamel
        wrote on last edited by
        #3

        Ahh, yes, I see what you mean - I have modified my code based on your feedback and it is working correctly now.

        Thank you very much for your help!

        Simon

        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