Automic Workload Automation

  • 1.  To determine if a variable defined / declared

    Posted Feb 02, 2018 04:32 AM
    Is there a way to determine if a variable is defined or declared on run time before it is actually executed ?
    I tried using GET_DATATYPE(variable) to see if variable is declared or not based on the data type that was returned,  but its just returning blank response.

    Please suggest..


  • 2.  To determine if a variable defined / declared
    Best Answer

    Posted Feb 02, 2018 04:56 AM
    I don't know of a function to find out if a variable is defined in Automic script.

    There is a rather silly trick though: You can initialize any variable by itself, like so:

    :set &dirty_hack# = &dirty_hack#

    If &dirty_hack# had a value before, that value will be retained. If &dirty_hack# was not initialized, it will now be initialized and empty, so you can distinguish with:

    :if &dirty_hack# = ""
    :  print "empty"
    :else
    :  print &dirty_hack#
    :endif

    And more importantly, your script will now not fail with an U00021719: Undefined Variable error. At the expense of making your script a little bit larger, wasting a few bytes and CPU cycles, and being a bit silly.

    Kudos once more to MatthiasSchelp for pointing me to this.


  • 3.  To determine if a variable defined / declared

    Posted Feb 02, 2018 04:57 AM
    Hi

    unfortunately not out of the box...

    in short you can use e.g. tis code snippet:

    :SET &SCRIPTVARA# = "&SCRIPTVARA#"
    :IF &SCRIPTVARA# = "" OR " "
    !   FURTHER CODE to avoid an unset (=empty) Scriptvara
    :ENDIF


    here was a discussion about that with lots of informaton.
    https://community.automic.com/discussion/488/how-to-test-whether-a-variable-is-set

    cheers, Wolfgang


  • 4.  To determine if a variable defined / declared

    Posted Feb 02, 2018 05:13 AM
    Thanks Carsten Schmitz & Wolfgang Brueckler.
    Can you tell me how this function : GET_DATATYPE(variable) works. I tried calling this function but its just a blank response.


  • 5.  To determine if a variable defined / declared

    Posted Feb 02, 2018 05:18 AM
    I don't know of :GET_DATATYPE, I can not find it in the Automic documents or in Google. Can you let us know where you found it? Thanks!


  • 6.  To determine if a variable defined / declared

    Posted Feb 02, 2018 05:22 AM
    I know of :GET_OBJECT_TYPE, but it is no use for script variables. It only works for persistent objects, such as Jobs or probably VARA objects.


  • 7.  To determine if a variable defined / declared

    Posted Feb 02, 2018 10:13 AM
    Carsten Schmitz : You can check directly in automic by typing GET_ and Ctrl + Space to see list. However, even i do not see in documentation. Also, I see that it accepts variable as a parameter. So, I just assume it should return the data type (Signed, Unsigned, String and float) as a result.


  • 8.  To determine if a variable defined / declared

    Posted Feb 02, 2018 10:22 AM
    Sai_Krishna_10325

    Thanks, that's interresting. But I now remember a similar thing: Automic ships a file that is seemingly used for syntax checking in the script editor. I think it's called syntax.bin or something like that. I looked through it a long while ago, and found functions that were in it, but not fully implemented in the engine.

    GET_DATATYPE may be one of those, a placeholder for future implementation, or an abandoned feature.

    Best regards and have a good weekend,
    Carsten


  • 9.  To determine if a variable defined / declared

    Posted Feb 02, 2018 10:32 AM
    Thanks Carsten Schmitz  :)