Environment Variables
I have an extension tool task that generates a random value.
This random value is formed by a fix value + current date + randomvalue.
The fix value is stored as an environment variable, that changes in any environment
I would like to add this value to the code, but all I get is the name of this variable.
This is my code
var SOAPUtil = Packages.soaptest.api.SOAPUtil
function GenerateUniqueID(input, context) {
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var hotel = context.getDataSourceValueAsString("$[Env_ID]")
var currentDate= hotel + year + month + day
var randomnumber=Math.floor(Math.random()*1000)
var randomstring=currentDate+randomnumber.toString()
return SOAPUtil.getXMLFromString([randomstring])
}
Thanks
Comments
-
Hi,
Instead of using context.getDataSourceValueAsString(), you'll want to use context.getEnvironmentVariableValue().
Also, simply pass in the name of the variable, there's no need to apply ${} syntax on it. So you should swap the following line:
var hotel = context.getDataSourceValueAsString("$[Env_ID]")
with:
var hotel = context.getEnvironmentVariableValue("Env_ID")
You can find more on the available methods by going to Parasoft > Help > Parasoft SOAtest Extensibility APIHi,
I have an extension tool task that generates a random value.
This random value is formed by a fix value + current date + randomvalue.
The fix value is stored as an environment variable, that changes in any environment
I would like to add this value to the code, but all I get is the name of this variable.
This is my code
var SOAPUtil = Packages.soaptest.api.SOAPUtil
function GenerateUniqueID(input, context) {
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var hotel = context.getDataSourceValueAsString("$[Env_ID]")
var currentDate= hotel + year + month + day
var randomnumber=Math.floor(Math.random()*1000)
var randomstring=currentDate+randomnumber.toString()
return SOAPUtil.getXMLFromString([randomstring])
}
Thanks0 -
Excellent!
It worked as I wanted.
Thanks for your help
EugeniaHi,
Instead of using context.getDataSourceValueAsString(), you'll want to use context.getEnvironmentVariableValue().
Also, simply pass in the name of the variable, there's no need to apply ${} syntax on it. So you should swap the following line:
var hotel = context.getDataSourceValueAsString("$[Env_ID]")
with:
var hotel = context.getEnvironmentVariableValue("Env_ID")
You can find more on the available methods by going to Parasoft > Help > Parasoft SOAtest Extensibility APIHi,
I have an extension tool task that generates a random value.
This random value is formed by a fix value + current date + randomvalue.
The fix value is stored as an environment variable, that changes in any environment
I would like to add this value to the code, but all I get is the name of this variable.
This is my code
var SOAPUtil = Packages.soaptest.api.SOAPUtil
function GenerateUniqueID(input, context) {
var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate()
var year = currentTime.getFullYear()
var hotel = context.getDataSourceValueAsString("$[Env_ID]")
var currentDate= hotel + year + month + day
var randomnumber=Math.floor(Math.random()*1000)
var randomstring=currentDate+randomnumber.toString()
return SOAPUtil.getXMLFromString([randomstring])
}
Thanks0