Forum Discussion

MGS10319's avatar
MGS10319
New Contributor
11 years ago

[Res]Using a Property Transfer Value in Data Source Query

I would like to use a value obtained in a Property Transfer step in a Data Source but the query directly inserts the value. It looks like this:

Select count(*)
From odsmgr.boxinvtry
@odsp
Where BNUMB Like ${GetBoxNum#Box}

${GetBoxNum#Box} is interpreted as "SASJH1656" and so the query tries to run as:

Select count(*)
From odsmgr.boxinvtry
@odsp
Where BNUMB Like "SASJH1656"

and returns an error invalid identifier.

If I go to the properties step where the value is stored from the transfer and update from SASJH1656 to '%SASJH1656%', the query runs fine. Is there a syntax I can use in the query to use this value and encapsulate in '%...%' or might I need some Groovy script to perform string manipulation? Thank you.

2 Replies

  • Hi!
    MGS10319 wrote:
    Is there a syntax I can use in the query to use this value and encapsulate in '%...%' or might I need some Groovy script to perform string manipulation?

    You can insert a Groovy TestStep before the SQL query, containing this code:
    box = "${GetBoxNum#Box}" // extract the Property to a Groovy variable
    box = "%$box%" // manipulate the string
    testRunner.testCase.setPropertyValue( "boxWithPercentageSigns", box) // store as a TestCase Property

    This will convert MY_VALUE (from GetBoxNum#Box) to %MY_VALUE% and store it in a TestCase Property called boxWithPercentageSigns.

    Let me know if this helps!

    Henrik O
    SmartBear Software
  • MGS10319's avatar
    MGS10319
    New Contributor
    Thank you very much. I used this and it works well!

    def box = context.expand( '${GetBoxNum#Box}' )
    box = "'%$box%'" // manipulate the string
    testRunner.testCase.setPropertyValue( "boxWithPercentageSigns", box) // store as a TestCase Property