global variable in tcl proc – fails when move the proc

Clovertech Forums Read Only Archives Cloverleaf Cloverleaf global variable in tcl proc – fails when move the proc

  • Creator
    Topic
  • #51150
    Kenadi Moore
    Participant

      We have a tcl proc that uses a global variable.  When it is used in the TPS Inbound Data location, it works fine.  When it is moved and used as a pre proc on a route, it errors because it doesn’t recognize the variable.  What is different about placing it in those 2 locations.  Here is the beginning of the TCL up to where it errors:

      proc merge_A02 { args } {

         global A02_save A02_svmsg

         keylget args MODE mode                      ;# Fetch mode

         switch -exact — $mode {

             start {

                 # Perform special init functions

                 # N.B.: there may or may not be a MSGID key in args

                 set A02_save 0;set A02_svmsg “”

                 return “”

             }

             run {

                 # ‘run’ mode always has a MSGID; fetch and process it

                 keylget args MSGID mh

                 set message [msgget $mh]

                 set evn4 [ getField “$message” EVN 4 0]

                 if { ![regexp {A02} $message] } {

                     return “{CONTINUE $mh}”

                 }

                 if { [cequal $evn4 “SWAP”] } {

                     if {$A02_save} {

      And here is the error:

      can’t read “A02_save”: no such variable

         while executing

      “if {$A02_save} {

      Thanks,

      Kenadi Moore

      OhioHealth

    Viewing 4 reply threads
    • Author
      Replies
      • #68955
        Jim Kosloskey
        Participant

          Kenadi,

          There is no start mode in xlt-pre and that is where the global is being set.

          email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

        • #68956
          Kenadi Moore
          Participant

            Since I couldn’t initialize the variables in the start portion of the tcl proc, Jim gave me a great suggestion to use “info exists” to see if the variables exist.  If not, they can be initialized at that time.  This takes place at the very beginning of the code and works great!

            Thanks Jim!!

            -Kenadi

          • #68957
            Tim Pancost
            Participant

              Not true that there is no start mode in xlt-pre, it’s just that it doesn’t happen by default.  If you want route-detail pre/post procs to be executed in start mode, you need to check the “Run Translation Procs in start-mode” box in Process Configuration for the process where the translation is happening.  You should be good to go then.

              HTH,

              TIM

              Tim Pancost
              Trinity Health

            • #68958
              Jim Kosloskey
              Participant

                Tim,

                I had forgotten about that (never actually used it).

                Kenadi,

                Let us know if that took care of your issue.

                email: jim.kosloskey@jim-kosloskey.com 29+ years Cloverleaf, 59 years IT - old fart.

              • #68959
                Kenadi Moore
                Participant

                  Jim,

                  I used your info exists solution and that worked great.  Tim’s suggestion would probably work as well.

                  -Kenadi

              Viewing 4 reply threads
              • The forum ‘Cloverleaf’ is closed to new topics and replies.