Environment Variables

LegacyForumLegacyForum Posts: 1,669 ✭✭
edited December 2016 in SOAtest
How to add environment variables to an Extension Tool Test
Hi,

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
Tagged:

Comments

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    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 API

    Hi,

    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

  • LegacyForumLegacyForum Posts: 1,669 ✭✭
    Excellent!

    It worked as I wanted.

    Thanks for your help

    Eugenia

    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 API


    Hi,

    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

Sign In or Register to comment.