I want to declare a global variable and put today’s date into that variable and then enter the variable in a Date field (in application).
Can anyone help me here by writing the commands for above ?
And also let me know how I can change the Date format permanently to 09/29/2014 i.e. MM/DD/YYYY ?
Here is a simple example page that shows a few different ways to declare global variables: http://docs.testplant.com/?q=content/global-variables
You can either formally declare them at the beginning of a handler, or you can declare them in-line.
To change the date format to MM/DD/YYYY, you will need to set the date property of the timeformat global property to “%m/%d/%Y”, like this:
put the timeformat.date -- puts "%m/%d/%y"
put the date -- puts "09/30/14"
set the timeformat.date to "%m/%d/%Y"
put the date -- puts "09/30/2014"
You can also use the pre-defined variable “Today” to reference today’s date, but it uses the international date format “%Y-%m-%d”, and that would have to be formatted separately. For instance, if I execute
But I am unable to access the variable in a Script of one Suite which I have expressed as global in another Script of same Suite.
global variable_name
Isn’t it the syntax for making a variable global or am I missing something here ?
Do I need to declare that variable in the Script where I am using it ? If so then please let me know how to do this ?
Yes, it is necessary to declare global variables in each handler. You must either declare it at the beginning of the handler, or in line as you use it. While it requires slightly more code (one word!), it can help to declare in-line just to help you keep track of which variables are global and which aren’t.
put "happy" into global myvar
myhandler
called.myfunction
to handle myhandler
global myvar -- declared at the beginning of hte handler
log myvar
end myhandler
Contents of Called.Myfunction:
to handle myfunction
log global myvar -- declared in line
end myfunction