While Controller is not looping all the values in the array from Regex( -1 ) results - while-loop

Im having the requirement like i need to loop through all the values that are capturing from regex with match No -1
ThreadGroup
---Req1
---Req2
---RegEx: with Match No. -1 (Debug Sampler shows match count : **18** )
---JSR223 Sampler ( Setting the counter value to 1 --**vars.put("counter1","1");**)
---While Controller ( **${__javaScript(parseInt(vars.get("counter1"))<=(${Task_matchNr}),)}** )
----Http req inside While controller
----JSR223 Sampler(Increasing the counter value by 1 everytime till Task_matchNr --**counter = counter+1; vars.put("counter1",Integer.toString(counter));**
Everytime it will execute till 11th value correctly and again it start executing from 1st value without exiting the loop
Could someone please help.

You don't need the counter as While Controller exposes current iteration via ${__jm__While Controller__idx} (since JMeter 5.0)
You're comparing integer to a string, you should do something like parseInt("${Task_matchNr}") `
It's better to use more performing function than JavaScript, for example __jexl3(), the relevant syntax would be something like:
${__jexl3("${Task_matchNr}" != "${__jm__While Controller__idx}",)}
Wouldn't be easier to use ForEach Controller instead?

Related

How to run while controller a number of times until i get a result code

I have the following doubt:
I need to run my test i.e. HTTP sampler until i get a status code >11 and the maximum number of times I need to run while loop is 20. As soon as i get a status code > 11 the loop should end. How do I achieve that.
my while loop has condition
:
${__javaScript(${Status_Code}<"11" && ${Status_Code}!="11",)}
You can use ${__jm__While Controller__idx} pre-defined variable in order to define the maximum number of iterations for the While Controller
Since JMeter 3.1 you should be preferring __groovy() function as Groovy performance is much better than other languages
Assuming above 2 points I would suggest refactoring your While Controller's condition to be:
${__groovy((vars.get('__jm__While Controller__idx') as int) < 20 && (vars.get('Status_Code') as int) < 11 ,)}

Having Issue on Field Calculator With Python in ArcMap

I have tried all of below snippets to use Python Parser in Field Calculator and update the values of a field called type based on a filed called MamerMN but in all of them I am getting Syntax error in Geoprocessing result window!
if !MamerMN! <= 0.151560:
return 1
and
if (!MamerMN! <= 0.151560):
return 1
and
if (MamerMN <= 0.151560):
return 1
and
def(MamerMN)
if MamerMN <= 0.151560:
return 1
and
def(MamerMN)
if (MamerMN <= 0.151560):
return 1
Can you please let me know what I am doing wrong?
You are writing your functions wrong. In the Field Calculator, make sure you check 'Show Codeblock' so the Pre-Logic Script Code box appears. Inside the Pre-Logic box, write your function-
def calcValue(mamerMN):
if mamerMN <= 0.151560:
return 1
and then in the box under, where it says the field_name =
you should write the name of the function and the field value you are passing to it surrounded by exclamations. So if your function above is named calcValue you would write
calcValue(!mamerMN!)
Without seeing a graphic of what your Field Calculator looks like, I suspect #csterling is probably right. However, an alternative is to just Select by Attribute where "mamerMN" <= 0.151560, then Field Calculate your selected features to 1 the regular way without necessitating a codeblock.

Zoho Creator making a custom function for a report

Trying to wrap my head around zoho creator, its not as simple as they make it out to be for building apps… I have an inventory database, and i have four fields that I call to fill a field called Inventory Number (Inv_Num1) –
First Name (First_Name)
Last Name (Last_Name)
Year (Year)
Number (Number)
I have a Custom Function script that I call through a Custom Action in the form report. What I am trying to do is upload a CSV file with 900 entries. Of course, not all of those have those values (first/last/number) so I need to bulk edit all of them. However when I do the bulk edit, the Inv_Num1 field is not updated with the new values. I use the custom action to populate the Inv_Num1 field with the values of the other 4 fields.
Heres is my script:
void onetime.UpdateInv()
{
for each Inventory_Record in Management
{
FN = Inventory_Record.First_Name.subString(0,1);
LN = Inventory_Record.Last_Name.subString(0,1);
YR = Inventory_Record.Year.subString(2,4);
NO = Inventory_Record.Number;
outputstr = FN + LN + YR + NO;
Inventory_Record.Inv_Num1 = outputstr;
}
}
I get this error back when I try to run this function
Error.
Error in executing UpdateInv workflow.
Error in executing For Each Record task.
Error in executing Set Variable task. Unable to update template variable FN.
Error evaluating STRING expression :
Even though there is a First Name for example, it still thinks there is none. This only happens on the fields I changed with Bulk Edit. If I do each one by hand, then the custom action works—but of course then the Inv_Num1 is already updated through my edit on success functions and makes the whole thing moot.
this may be one year late, you might have found the solution but just to highlight, the error u were facing was just due to the null value in first name.
you just have put a null check on each field and u r good to go.
you can generate the inv_number on the time of bulk uploading also by adding null check in the same code on and placing the code on Add> On Submt.( just the part inside the loop )
the Better option would be using a formula field, you just have to put this formula in that formula field and you'll get your inventory_number autogenerated , you can rename the formula_field to Inv Number or whaterver u want.
Since you are using substring directly in year Field, I am assuming the
year field as string.else you would have to user Year.tostring().substring(2,4) & instead of if(Year=="","",...) you have to put if(Year==null , null,...);
so here's the formula
if(First_Name=="","",First_Name.subString(0,1))+if(Last_Name =="","",Last_Name.subString(0,1)) + if(Year=="","",Year.subString(2,4)+Number
Let me know ur response if u implement this.
Without knowing the datatype its difficult to fix, but making the assumption that your Inventory_Record.number is a numeric data item you are adding a string to a number:
The "+" is used for string Concatenation - Joiner but it also adds two numbers together so think "a" + "b" = "ab" for strings but for numbers 1 + 2 = 3.
All good, but when you do "a" + 2 the system doesn't know whether to add or concatenate so gives an error.

Orientdb sql auto increment: id is always null (sql batch, update increment, variables)

I was looking at another question in stackoverflow regarding auto increment fields in orientdb, where one of the answers was to create our own vertex with counter field.
However, when I'm trying to execute the following code (both java api and console script batch), It is not working.
Do note however that the id is returned good (did some debug attempts, returning the id variable only), and the vertex is created.
However, the vertex id is always null (unless I set it explicit, that is).
The script:
script sql
LET id = UPDATE CCounter INCREMENT value=1 RETURN AFTER $current WHERE name='session'
LET csession = CREATE VERTEX CDate SET id=$id.result, meet_date='2015-01-01 15:23:00'
end
I tried playing around with $id and $current , but nothing seems to work.
Currently I am doing it in a 2-transaction mode; one to get the id, and another to create the vertex. I really hope there is a better way though.
P.S.
I am using version 2.0-M2
You should execute
LET csession = CREATE VERTEX CDate SET id=$id.value, meet_date='2015-01-01 15:23:00'
Note the $id.value in place of $id.result.
As stated in a comment to Lvca, the answer was:
(1) Change the field name. Id seems to be reserved (ish). It's probably possible to still bypass it and use a field named 'id', but I didn't want to mess around with it.
(2) From some reason, the result was a collection (shown as '[id]'). It took me some time to figure it out, but I just had to choose the first value from it.
(3) Also, there are 2 'values' here. One of the field ($current.value), and the second one(not sure where it's coming from).
Final solution that works:
script sql
LET id = UPDATE CCounter INCREMENT value = 1 RETURN AFTER $current.value WHERE name='session'
LET csession = CREATE VERTEX CDate SET data_id=$id[0].value, meet_date='2015-01-01 15:23:00'
end

JMeter regex extractor forEach controller

I'm creating some tests with JMeter, the situation is very simple, I have a search page with a list of results, and I have to retrieve from this results some values to use in the next request.
Those results are around 350, I don't need them all.
I used the RegexExtractor to retrieve those results and it works (I setted it to retrieve just 10 results), but now I don't know how to access the results inside a LoopCounter.
The extractor put the results into a variable named Result.
The problem is that I don't know hot to build dinamically the name of a variable.
Do I have to use some function like _p()??
I can access the variable just putting the static name Result_0_g1
Inside the LoopCounter I putted also a Counter to store the loop count into the variable index
Thank you
EDIT:
SOLVED I have to write:
${__V(Result_${index}_g1)
You have to reference the variable with the function:
${__V(Result_${index}_g1)
...Just for collection.
See also this post for another implementation (case without using ForEach Controller):
ThreadGroup
HttpSampler
Regex Extractor (variableName = links)
WhileController(${__javaScript(${C} < ${links_matchNr})})
HTTPSampler use ${__V(links_${C})} to access the current result
Counter (start=1, increment=1, maximum=${links_matchNr}, referenceName=C)
Use the ForEach Controller - it's specifically designed for this purpose and does exactly what you want.
You may use ForEach Controller:
ThreadGroup
YourSampler
Regular Expression Extractor (match -1, any template)
Foreach controller
Counter(Maximum -> ${Result_matchNr} , Rf Name -> index)
LinkSamplerUsingParsedData(use -> ${__V(Result_${index}_g1)}
Now, if you want to iterate to all groups, you need another foreach to do that. As you know which group represent what value, you can use this way.