How to pass variable from one Action to Other in UFT

user3435903 picture user3435903 · Aug 21, 2014 · Viewed 21.3k times · Source

I have Action 1 where i am querying the db and getting a field which i am storing in the variable (lets say x). In Actions 2, i am again querying the db where i want to use the value stored in x in the where clause.

Snippet from Action 1:

SQL1 =  "   SELECT      Identitynumber " &_
        "   FROM        VLC_CRM.dbo.Person " &_
        "   WHERE       Identitynumber = '" &IdentityNumber_ui&"'"


Set oRecordSet = oConnection.Execute(SQL1)

Do While NOT oRecordSet.EOF
    IdentityNumber_db_tmp = CStr(oRecordSet.Fields("Identitynumber").Value)
    IdentityNumber_db = RTrim(IdentityNumber_db_tmp)
    oRecordSet.MoveNext
Loop

Action 2 SQL (i want to use IdentityNumber_db from Action 1 in my Where Clause below)

SQL1 =      "   SELECT  TOP 1   CAST(la.LogonDate AS DATE) AS LogonDate," &_
            "                   la.LogonDate AS LastLogonDateTime"&_
            "   FROM            dbo.LogonAudit la" &_
            "   INNER JOIN      dbo.Person p" &_
            "   ON              la.EntityID = p.PersonID" &_
            "   WHERE           p.IdentityNumber = '"&IdentityNumber_db&"'"  &_
            "   ORDER BY        LastLogonDateTime DESC"

Can someone please suggest how i can pass this value from Action 1 to Action 2 so i can use it in my SQL query?

Answer

donubas picture donubas · Mar 10, 2016

Version: UFT 12.51

Use the syntax: RunAction strActionName, oneIteration, Param1, Param2

  1. The Input Parameters <Param1>, <Param2> is declared in your first Action, I called it Action1.
  2. Pass the value to your Action1 local variable, example: Param1 = "a1_var1 --> from Action 1"
  3. Execute the RunAction command to pass the value, RunAction "Action2", oneIteration, Param1
  4. In Action2, I retrieved the Parameter Value and store in Param2 Action 2 Local variable, Param2 = Parameter("Param1")

Refer to screenshot.
enter image description here