Automic Workload Automation

Expand all | Collapse all

Automic Scripting: Create Variables with Dynamic Names and Dynamic Values (via Indirect references)

  • 1.  Automic Scripting: Create Variables with Dynamic Names and Dynamic Values (via Indirect references)

    Posted 12-19-2017 09:14 AM
      |   view attached
    It is now possible in v12.1 to dynamically create Automic Variables (ex:&MYVAR#) in a script (Pre or PostProcess included) without knowing the names of the variables prior (to my knowledge this was not possible before).

    Here is an example:

    a JOBS object returns an arbitrary output in the following format: 
        MATCHWASFOUND|VAR1#|U02001096
        MATCHWASFOUND|VAR2#|100:STORE.CONN.UPDATE/CONN_UPDATE
        MATCHWASFOUND|MYOTHERVAR#|Some Value here
    • the number of lines varies and isunpredictable
    • the second column (which eventually we want to use as the name of an automic variable) is alwaysunpredictable


    Our goal:

      After we are done with the postprocessing, we want: 

    • set as many Automic Variables as I have lines that start with "MATCHWASFOUND"
    • Use the second column as the Automic Variable name
    • Use the third column as the automic Variable value


    So, in this case, once done with postprocessing, I want the following automic variables to exist:

    • &VAR1# = “U02001096”
    • &VAR2# = “100:STORE.CONN.UPDATE/CONN_UPDATE”
    • &MYOTHERVAR# = “Some Value here”


     In order do so, we will use a combo of the :CREATE_PROCESS (and related commands) and :GENERATE_SCRIPT_VARS commands


    Important Note: to leverage GENERATE_SCRIPT_VARS you need to set GENERATE_UNDEFINED_SCRIPT_VARS to Y in UC_SYSTEM_SETTINGS


    Here is the content of the PostProcess Tab:

     

    ! Create a new Data Sequence that will contain the new Variables' Names and Values ! Conceptually it is similar to a "virtual" VARA object with one Key and one Column :SET &VarHND# = CREATE_PROCESS(NEW) ! normal processing of the REP :SET &HND# = PREP_PROCESS_REPORT("JOBS",, "REP",,"COL=DELIMITER", "DELIMITER=*|*") :PROCESS &HND# :  SET &MatchFound# = GET_PROCESS_LINE(&HND#,1) :  IF STR_STARTS_WITH(&MatchFound#, "MATCHWASFOUND") = "Y" :    SET &VarName# = GET_PROCESS_LINE(&HND#,2) :    SET &Value# = GET_PROCESS_LINE(&HND#,3) :    PRINT  "&Varname# !! &VALUE# !! &MatchFound#" ! Add data to the new Data Sequence (delimiter is |) :    SET &CHECK# = PUT_PROCESS_LINE(&VarHND#, "&VarName#|&Value#", "|") :  ENDIF :ENDPROCESS :SET &RET# = SAVE_PROCESS(&VarHND#) ! Generate all Variables stored in the data sequence :SET &ret# = generate_script_vars(&VarHND#, , UPDATE) :P &ret# :P &&VAR2#:&VAR2# :P &&VAR1#:&VAR1#


    and here is the corresponding output generated: &VAR1# and &VAR2# now exist and their respective values correspond the column 3 of the original output:

    m04ggds0ko0z.png

    An export of the corresponding JOBS Object is attached.


     

    Attachment(s)



  • 2.  Automic Scripting: Create Variables with Dynamic Names and Dynamic Values (via Indirect references)

    Posted 12-19-2017 09:16 AM
    Michael_Lowry i believe you had a thread open around this topic, maybe this will help?


  • 3.  Automic Scripting: Create Variables with Dynamic Names and Dynamic Values (via Indirect references)

    Posted 12-20-2017 11:38 AM
    Michael_Lowry i believe you had a thread open around this topic, maybe this will help?
    brendan_sapience_automic: Your approach obviates the need to create a temporary static VARA. Good idea.

    The documentation does not provide a complete example of how to use GENERATE_SCRIPT_VARS with a data sequence, so thanks for providing this.


  • 4.  Automic Scripting: Create Variables with Dynamic Names and Dynamic Values (via Indirect references)

    Posted 12-20-2017 02:10 PM
    a large part of the credit goes to kay_koll_automic !! he came up with the solution.


  • 5.  Automic Scripting: Create Variables with Dynamic Names and Dynamic Values (via Indirect references)

    Posted 12-20-2017 02:11 PM
    To go further with this use case, it would be interesting to have a command that can publish those dynamic variables to the parent workflow and top workflow: that would be VERY useful for ARA and ASO as well. I have opened a corresponding "idea" and talked to PM about it already.

    I imagine we could simply extend the actual :PUBLISH command to work not just on variables or Arrays, but also on Data Sequences.



  • 6.  Automic Scripting: Create Variables with Dynamic Names and Dynamic Values (via Indirect references)

    Posted 01-03-2018 04:32 AM

    Brendan Sapience wrote:

    To go further with this use case, it would be interesting to have a command that can publish those dynamic variables to the parent workflow and top workflow: that would be VERY useful for ARA and ASO as well. I have opened a corresponding "idea" and talked to PM about it already.
    I imagine we could simply extend the actual :PUBLISH command to work not just on variables or Arrays, but also on Data Sequences.

    For those who are interested in voting for this idea, here is the link:

    Allow the :PUBLISH command to work on Data Sequences for Automic Scripting