How do I pass a value back to the calling script

Question: How can I call a script in a different suite and return a value from that other suite back to the main runner.script and use it as a parameter while calling a script in a third suite from the primary bat.suite?

The issue seems to be that I don't know how to bring back from the second script and access the value in the main runner script.

I have three suites: my bat.suite, lib.suite and reference.suite


In the three suites I use these three scripts. I open the suites and have access to the scripts.

There are three scripts I run.
runner.script -bat.suite
utils.script - lib.suite
tools.script. - reference.suite

In bat.Runner.script I call lib.utils.sendReceive with a parameter myTimeOut
Then lib.utils.sendReceive records how long outlook takes for a send/receive and puts that info into a property called sndRcvTime

Goal: In my bat.Runner Script I want to call reference.tools.email and pass it sndRcvTime (from lib.utils.sendReceive) and also pass reference.tools.email some other properties which are in the bat.runner.script

Thanks
-Tom

Comments

  • A quick question: Are these entire scripts you are calling, or handlers/functions you're calling from within specific scripts? I don't think there's a difference (SenseTalkDoug will correct me if I'm wrong), so hopefully this (untested) solution will work. First, add a return statement to each of the scripts you call:
    //other script stuff...
    return sndRcvTime
    
    This will ensure that "the result" has the right value.

    Next, modify how you call your other script:
    lib.utils.sendReceive param,param, param
    put the result into someVar
    
    Now you should be able to pass that on as a parameter.

    As an aside question to Doug or Matt or Ellissin, could that be shortened onto one line?
    email (the result of myScript param), someOtherParameter
    
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Sure. To simplify it a bit and avoid having to use "the result" function to access the value, just call the other script as a function, something like this:
    put utils.sendReceive() into someVar
    
    Note that to be able to easily call a script in another suite, you should insert that suite into either the initialSuites (checked before the current suite) or the finalSuites (checked after the current suite -- this is more often what you want).

    So for what manradion asked for (and doing both calls on the same line), it might be done like this (in the runner script in the bat suite):
    insert "/path/to/lib.suite" into the finalSuites
    insert "/path/to/reference.suite" into the finalSuites
    
    tools.email utils.sendReceive(myTimeout), anotherParam
    
  • I'm new, I'm thinking that these are handlers/functions inside scripts:

    **********************
    bat.runner.script
    *******************
    Properties
    myTimeOut
    end Properties

    OpenSuite "lib.suite
    OpenSuite "reference.suite

    run lib.utils.sendReceive myTimeOut


    *********************************
    lib.utils.script
    *******************
    to sendReceive myTimeOut
    put the time into startTime
    TypeText "F9"
    WaitFor myTimeOut ("Send and Receive Complete")
    put the time - startTime into SndRcvTime
    end sendReceive
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Looks like we both posted at once... ;-)

    You're getting close. As Allen mentioned, you need to return a value from the sendReceive handler in the utils script, so add this line right before the "end sendReceive" line:
    return SndRcvTime
    
    Then call it as I showed in my last post.

    BTW, your script uses OpenSuite, which is fine. However, I generally suggest inserting suites into the finalSuites instead, which is a newer, more flexible mechanism that was added in order to overcome some limitations that were present in the older OpenSuite/CloseSuite commands.
  • It is actually messier.

    bat.runner.script

    calls lib.utils.initialSndRcv myTimeOut

    lib.utils.initalSndRcv myTimeOut
    Calls lib.utils.sendRevieve myTimeOut

    and lib.utils.sendReceive myTimeOut
    generates sndRcvtime

    What is preferred method to bring lib.utils.sendReveive value sndRcvTime back to bat.runner.script?
  • SenseTalkDougSenseTalkDoug ForumAdmin admin
    Well, it's just one more step in that case:
    (* utils.script *)
    
    to initalSndRcv aTimeOut
        -- do stuff here
        put sendReceive(aTimeOut) into sendReceiveTime
        -- do more stuff, maybe
        return sendReceiveTime
    end initialSndRcv
    
    to sendRecieve aTimeOut
        -- do whatever processing here
        return SndRcvTime
    end sendReceive
    
    and then call initialSndRcv from your bat.script:
    put initialSndRcv(myTimeOut) into someVar
    
    Does that make it more clear?
  • Groovy, it all comes together
    Thanks
Sign In or Register to comment.