Re: Passing a value to a reusable Action
A bunch of different things you can do.
First (not recommended, but sometimes it's OK) is to simply write your reusable action to look at the datasheet in the calling action. Clearly, if this reusable action needs to be available to more than one script that might call it, it won't work. But if you never need to use this action in any way other than when one specific script calls it, this is the easiest solution. Do this:
strState = DataTable("State Parameter", "Sheet for Calling Action")
Another way is to store the item before you call the reusable action. Two possibilites here work really well: store it in an Environment Variable or store it in the datasheet of the reusable action. There are other places to store it, but these two are fairly easy.
Environment("StateParameter") = DataTable("StateParameter")
DataTable("StateParameter", "Sheet for Reusable Action") = DataTable("StateParameter")
The reusable action gets the data by
strState = Environment("StateParameter")
strState = DataTable("StateParameter")
Finally, if you are using QTP Version 8.0 or later, the RunAction statement allows you to pass variables.
First you define the parameter in your reusable action as an input parameter. Then you define it for the script in which that action resides and link the script parameter to the action parameter. Then you create your RunAction command like this:
RunAction "ActionName [ScriptName]", oneIteration, ParameterYouSend
And your reusable action uses this parameter like any other variable name. For example, if you defined the action's input parameter as "pramState" your case statement would look like this:
I personally prefer the latter method because you don't have to create additional lines of code to store or retrieve the data - it is almost like a function call.
But that final method does take a bit more to set it up and it's not abundantly clear from the helpfiles how to do it. If you have questions, I have posted the entire process on this forum, you should be able to find it with a quick search.
Passing a value to a reusable Action
I want to create an action that I will call for multiple scripts. This action will answer questions depending on what state the main script is currently working on.
In the reusable action I want to create I will have a case statement:
The value strState comes from the datasheet which is in the calling action.
My question is how do I pass the value from the calling action to the action that is being called?
Any help would be appreciated. Thanks.