Write variable into DB

I have several tests measuring the performance of some forms and writing it into a DB

set myDB to (type:"odbc", DSN:"xy", user:"xy", password:"zy")
open database myDB

put table "anyTable" of myDB into myTable 
put now into startTime
Click something
WaitFor 60, something
put now minus startTime into entry 
log "something took" && entry
put first word of entry into durationTime
put formattedTime("%Y-%m-%d") into myTime

set newRow to (Name: "Test", Group: "someGroup", Environment: "bla", ExecutionDateTime: myTime, ExecutionDuration: durationTime, Id: 1)
add record newRow to myTable

close database myDB

Since I need to run these tests in different releases I’d like to use the ID column of MyTable to store in the release number. I have created a script X with a universal variable where I pass on the release number

universal MyVar
Put (20) into List
Put List into universal MyVar
Put MyVar

How do I use X in set newRow to (…Id:??) of my command without having to put it in each script separately? That is I want to call the script instead of defining a variable in each script.

Thank you in advance

I think you’re looking to pass a parameter. When you call a script that needs the release number, you pass it as part of the script call:

myOtherScript releaseNum

In myOtherScript, you declare a parameter on the first line of the script:

params release

Note that the parameter can be called anything that you would like; it doesn’t have to have the same name as the variable containing the value that you are passing. Then inside myOtherScript, you can refer to that parameter whenever you need the release number:

log release

You do still have to declare the parameter in any script that’s going to receive it, so it’s not a lot different in terms of the amount of code from declaring a global variable, but it is the preferred way of passing data between scripts.

Thanks Matt. I will try this.

I’d hoped I didn’t have to declare the parameter in every single script though.

Just to point something out. One of the benefits of SenseTalk is that you don’t HAVE to declare the parameters. (It’s ok to pass a parameter even if the other function doesn’t declare it).

The declaration makes it easy to refer to in your script but you can also use the param() function to refer to the parameters in order. Here’s a simple example that passes two parameters, neither is declared, but we print the second one:

myHandler "xyz", 123

on myHandler
	put param(2)
end myHandler