I am facing problem while using a variable inside another variable name for example check this : ${email_${count}} .
Here email is the variable name storing data from JDBC request sampler and as you might know data into variables gets stored like this : email_1 , email_2 and so on based on the rows we are extracting.
Now i don't want to write 10 variables manually like email_1 , email_2 , email_3 upto email_10 . i am using counter from 1 to 10 and counter reference variable name is count so my syntax is becoming as : ${email_${count}} . where email would be the variable from JDBC sampler and count is counter variable name . Basically i am appending counter variable to JDBC variable , but jmeter is treating it as a standalone variable .
Can anyone please help me in this matter. if you need further clarification let me know.
I am attaching screenshots below for more clarification.
Use __V function for evaluating variable inside a variable
${__V(A${N})} - works OK. A${N} becomes A1, and the __V function returns the value of A1
You should use it in your case:
${__V(email_${count})}
Or use __evalVar with similar syntax:
${__evalVar(email_${count})}
The evalVar function returns the result of evaluating an expression stored in a variable.
Related
I am creating an SSIS package which has an execute SQL task and it passes result set variable to a for each loop container.
My Sql Query is:
Select distinct code from house where active=1 and campus='W'
I want the execute sql task to run this query and assign its results to a variable which is passed to a for each loop container which should loop through all the values in the result set.
But my execute sql task fails with error:
The type of the value (DBNull) being assigned to variable
"User::house" differs from the current variable type (String)
Now i have done my research and i have tried assigning the variable datatype Object but did not work. I tried using cast in my sql query and that also did not work.
Since my query returns multiple rows and one column, i am not sure how i can assign a datatype to the whole query?
Sample:
Code
AR
BN
CN
It sounds like you have a variety of issues in here.
Result Set
The first is in your Execute SQL Task and the need for agreement between the Result Set specification and the data type of the Variable(s) specified in the Result Set tab. If you specify Full Resultset, then the receiving object must be of type System::Object and you will only have 1 result set. The type of Connection Manager (ODBC/OLE/ADO) used will determine how you specify it but it's infinitely searchable on these fine forums.
The other two options are Single Row and XML. In 13 years of working with SSIS, I've never had cause to specify XML. That leaves us with Single Row. For a Single Row Result Set, you need to provide a variable for each column returned and it needs to be correctly typed.
To correct your issue, you need to declare a second variable. I usually call my rsObject (record set object) and then specify the data type as System.Object.
For Each Loop Container
Your For Each Loop Container will then be set with an Enumerator of "Foreach ADO Enumerator" and then the ADO object source variable will become "User::rsObject"
In the Variable Mappings, you'll specify your variable User::house to index 0.
Testing
Given a sample set of source source data, you can verify that you have your Execute SQL Task correctly assigning a result set to our object and the Foreach Loop Container is properly populating our variable.
SELECT DISTINCT
code
FROM
(
VALUES
('ABC', 1, 'w')
, ('BCD', 1, 'w')
, ('CDE', 0, 'w')
, ('DEF', 1, 'w')
, ('EFG', 1, 'x')
) house(code, active, campus)
WHERE
active = 1
AND campus = 'w';
If you change the value of campus from w to something that doesn't exist, like f then things will continue to work.
However, the error you're receiving can only be generated if the code is a NULL
Add one more entry to the VALUES collection like
, (NULL, 1, 'w')
and when the For Each Loop Container hits that value, you will encounter the error you indicate
The type of the value (DBNull) being assigned to variable "User::house" differs from the current variable type (String)
Now what?
SSIS variables cannot change their data type, unless they're of type Object (but that's not the solution here). The "problem" is that you cannot store a NULL value in an SSIS variable (unless it's of type object). Therefore you need to either exclude the rows that return a NULL (AND code IS NOT NULL) or you need to cast the NULL into sentinel/placeholder value as a substitute (SELECT DISTINCT ISNULL(code, '') AS code). If an empty string is a valid value, then you need to find something that isn't - "billinkcisthegreatestever10123432" is unlikely to exist in your set of codes but that might be a bit excessive.
Finally, think about renaming your SSIS variable from house to code. You might be able to keep things straight but some day you'll hand this code over to someone else for maintenance and you don't want to confuse them.
A picturesque answer https://stackoverflow.com/a/13976990/181965
the variable "User::house" is string , so , did you use it in result set?
you need declare son "object" var for result set
result set
then declare a string variable for every single Code from your result
For Each Loop Container
good luck
Ive got two project level variables in TestComplete:
Var1 = ${#Var2} and Var2 = 123456789
using Log.Message(Project.Variables.Var1) should evaluate to "123456789" but it just prints ${#Var2} as string.
is there any way we can make it dynamic?
in particular I want to update the value of a variable defined in "ReadyAPI-Test Edit-Properties" page with the value from project's local or persistent property value. The reason is that this variable is not accessible using script, the only option available is to execute i.e. ReadyAPI.TestCase.Execute()
Thanks
This is not something that is usually done in TestComplete.
If you need to use this in a script, you can use the eval function. However, the syntax of the variable should contain a valid JavaScript code:
Var1 = "Var2"
Var2 = 123456789
Log.Message(eval(Var1));
If you do not have control over the format of the Var1 variable, you will need to create code that will parse the value of the variable and do the needed replacements.
I have one execute SQL Task in SSIS 2012 which has update statement. I want to pass a string variable in the where clause of this update statement. The update section is as below:
where coalesce(s1.iteration, '') not like '%?%' and s2.Iteration = '?'
Here, ? needs to be replaced with a string variable, which in this case would be 08152017. I have added the variable to the Parameter Mapping. Screenshot is attached.
The task executes successfully but does not updates the value in the intended column. It seems the query is not passing the value.What am I doing wrong? How do I check that the SQL inside the Execute SQL Task is actually getting the value from the variable?
First of all, when you set your variable in parameter mapping, make sure the datatype is NVARCHAR and not LONG.
Second you need to write your statement like this:
where coalesce(s1.iteration, '') not like '%?%' and s2.Iteration = ?
You dont need '' because your variable is already set as a string.
Try to hardcode your value in your variable to see if it passes. Otherwise, set a breakpoint on pre-execute to see wheter your variable has a value.
If your variable has a value and your SQL is not working, maybe you should look into your SQL. Maybe try it directly in SSMS to see if it actually runs or does anything.
In scenario ? is Integer type variable, then please use below format:
SELECT ? +' Hello World!'
The above does not require the use of an additional string variable.
Create a user variable with % on it, for example, variable name is Like_Var with data type String
"%" + #Orig_Var + "%"
Let's say, Orig_Var has a value of 08152017, therefore Like_Var will have %08152017%
Then use Like_Var on your parameter in Execute SQL Task as parameter 0, data type VARCHAR in Parameter Mapping
WHERE COALESCE(s1.iteration, '') NOT LIKE ?
AND s2.Iteration = ?
I've got the following problem:
I do gather that ProductId variable is assigned with the first value and then only that value is used when I refer to ${productId}.
I was trying to apply ${__counter()} to reference name in RegexExtractor,
but then BeanShellAssertion fails to set the property.
How should I properly work this around?
You can use __V() function in order to combine 2 variables.
I.e. if you have 2 variables like:
productId
counter
And would like to evaluate i.e. ${productId_1}, ${productId_2}, etc.
It should be as simple as:
${__V(productId${counter})}
Same approach applies to __counter() function:
${__V(productId_${__counter(,)})}
Demo:
See How to Use JMeter Functions posts series for comprehensive information on above and other functions
ProdGroup
please store the product Id property as prod_id_1, prod_id_2,...prod_id_n or according to you convenience
How to to that ?
in post processor "Parameters" section use ${__counter(FALSE,)} and in the script part try getting that String counter = arg[0] and convert that to integer and store it to a script variable by default arg[0] value is String
int c= arg[0] as Integer //this is groovystyle check in your way to convert as int
now props.put("prod_id_"+c,"extractedfrom_response")
BID:
In you Bid group add a user defined variable section add the variable
"prod_id" and value is empty
Define a counter start with the same counter 1 and give counter reference name [if your counter value in prod group was 0 then here also it must start with zero]
script sampler convert all the props to the variables
Enumeration e = props.propertyNames();
while (e.hasMoreElements()) {
String propertyName = e.nextElement().toString();
if (propertyName.startsWith("prod_id_")) {
vars.put(propertyName, props.getProperty(propertyName));
}
}
With this you have converted properties to variables named prod_id_1 ...to ... prod_id_n
In http sampler user reference as ${__V(prod_id_${counterreference in step 2})} will do your job
For each thread the counter will increment by default
user ${__threadNum} or ${counter reference name} in sampler labels for debugging.
Hope this helps. Please let us know if still problem is there.
I am using JasperStudio 5.6.0.final and the report is not generated dynamically from java code.
I have a problem with getting single value from parameter.
In the report I have a parameter A of a type List.
It is not a problem to use it in a clause as IN statement:
AND $X{IN, USER.ID_USER, A}
But I have a problem to get a single value from that list.
I know that my List has always 10 values.
So I want to use it in query, but I don't know how to write the statement:
AND USER.ID_USER = *first_value_of_list_A*
e.g.
AND USER.ID_USER = $P!{Atrybuty}.get(1)
doesn't work
I tried also to assign parameter value to a variable, but as I know it isn't possible to use variables in queryString.
So my question: How to get single value from parameter List in queryString.
What you need to do for this is use
AND $X{IN, USER.ID_USER, A}
Set A type as Collection and that will allow you to even have a single selection or multi selection or just a single value.
Hope that this helps.