Forum Discussion

jrziggy's avatar
jrziggy
New Contributor
4 months ago

Passing variable as index in property, Groovy

Hi.  I am having trouble getting a property to expand in Groovy using the right index after getting a list of data from a data source. I'm trying to pass the index to the property as a variable in th...
  • TNeuschwanger's avatar
    4 months ago

    Hello jrziggy 

    It looks like this is a little trick situation...  you need to expand the 'randomIndex' variable before the whole datasource reference is parameter expanded...

    The context.expand is operating on a string, so just manipulate it a little bit to get your number in there instead of the variable that references it...  be mindful of single quote use versus double quote use below.  Simple parameter replacement occurs when double quotes are used.  This sample just gets that variable replaced before the whole context.expands the full parameter.

    result = context.expand( '${DataSourceStationNumber#STATION_NUM::' + "$randomIndex" + '}' );

    Regards,

    Todd