Submit and vote on feature ideas.

Welcome to the new Parasoft forums! We hope you will enjoy the site and try out some of the new features, like sharing an idea you may have for one of our products or following a category.

Environment Variables

LegacyForum
LegacyForum Posts: 1,664 ✭✭
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

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    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

  • LegacyForum
    LegacyForum Posts: 1,664 ✭✭
    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