Get count variable instances with variables using REST API - camunda

I have the below variables
when i count the number of variable instances with the variable conventionCode, the api returns count = 1
http://localhost:8282/engine-rest/variable-instance/count?processInstanceIdIn=b622ad4d-9a11-11ec-937b-0242ac11000a&variableValues=conventionCode_eq_01018
when i count the number of variable instances with the variable exerciceFrameworkId, the api returns count = 1
http://localhost:8282/engine-rest/variable-instance/count?processInstanceIdIn=b622ad4d-9a11-11ec-937b-0242ac11000a&variableValues=exerciceFrameworkId_eq_SA-FR-LAB-6969284
The problem is when i use the two variables conventionCode and exerciceFrameworkId, the api returns count = 0
http://localhost:8282/engine-rest/variable-instance/count?processInstanceIdIn=b622ad4d-9a11-11ec-937b-0242ac11000a&variableValues=conventionCode_eq_01018,exerciceFrameworkId_eq_SA-FR-LAB-6969284

The API is focused on variables. So it will check each variable if your filters match.
In your example you defined 2 filters:
conventionCode_eq_01018
exerciceFrameworkId_eq_SA-FR-LAB-6969284
So for each variable with the name conventionCode and the value 01018 the first filter matches.
However, it is impossible that this matches to the 2. filter as its name is conventionCode and not exerciceFrameworkId.
So in the end you have no variables in your result.
That means it is a logical AND and not as you expected a logical OR.
See also the REST-API Reference

Related

Using Javascript IF function to create Google Tag Manager Variable

I'm trying to create a custom variable in Google Tag Manager. I need it to show a 0 value when...
A customer purchases using a discount code which contains the words 'Gift Voucher'
AND
It generates negative revenue.
Else it should just appear standard revenue (there are times when negative revenue is needed, hence why it should only appear as 0 when a gift voucher is used)
Ive tried the following
function () { if ({{Discount Code Used}} = str.includes("Gift Voucher") && {{Revenue}}<0 ) {return 0; } else { return {{Revenue}}; }}
But this is returning a undefined value
Is anyone able to help?
The first half of your if condition is a bit off:
{{Discount Code Used}} = str.includes('Gift Voucher')
The right way to use the .includes() method of a string is like this:
{{Discount Code Used}}.includes('Gift Voucher')
I would recommend using .indexOf() instead of .includes(), since it is supported by more browsers.
{{Discount Code Used}}.indexOf('Gift Voucher') !== -1
If it is still returning undefined, double check that Discount Code Used and Revenue are set to the correct values.

Camunda: query processes that do not have a specific variable

In Camunda (7.12) I can query processes by variable value:
runtimeService.createProcessInstanceQuery()
.variableValueEquals("someVar", "someValue")
.list();
I can even query processes for null-value variables:
runtimeService.createProcessInstanceQuery()
.variableValueEquals("someVar", null)
.list();
But how can I query processes that do not have variable someVar?
I am not sure why you wouldn't have figured that out, but if i am correct what i think you are looking for , then looks like its pretty simple . The ProcessInstanceQuery class has also a method called variableValueNotEquals(String name, Object value) , that allows you select the processes that do not match a variable . In the Camunda Java API Docs it is stated as :
variableValueNotEquals(String name, Object value)
Only select process instances which have a global variable with the given name, but with a different value than the passed value.
Documentation page for your reference:
https://docs.camunda.org/javadoc/camunda-bpm-platform/7.12/?org/camunda/bpm/engine/RuntimeService.html
So i believe you can simply do :
runtimeService.createProcessInstanceQuery()
.variableValueNotEquals("someVar", null)
.list();
Let me know if that helps you .
First, get list of ids of all process instances which have "someVar"
Second, get list of all process ids in camunda
Get ids, from second list, which are not contained in first list.
Here is Kotlin sample as it's shorter than Java code, but concept is the same:
val idsOfProcessesWithVar = runtimeService.createVariableInstanceQuery().variableName("someVar").list().map {
it.processInstanceId
}
val allProcessesIds = runtimeService.createProcessInstanceQuery().list().map { it.id }
allProcessesIds.minus(idsOfProcessesWithVar)

Keeping a constant number to a set, before it appends other numbers

I have a set of numbers which is generated real-time during running the code. In the snippet of code shown below with the function constant_set, the number generated real time are stored in the variable set_accepted_list_frozen. What i want to ask is, if i want to keep a constant number always in the set_accepted_list_frozen before the other numbers are appended to the list set_accepted_list_frozen, how should i proceed?
set_accepted_list_frozen = set()
def constant_set(set_accepted_list,set_forbidden_list):
global set_accepted_list_frozen
if num_accepted >= len(set_accepted_list_frozen):
for var in set_accepted_list:
if len(set_accepted_list_frozen) == num_accepted:
break
set_accepted_list_frozen.add(var)

Jmeter Regular Expression Extractor. How to save all returned values to a single variable?

I'm quite new to Jmeter and already spent numerous hours to figure it out.
What i'm trying to achieve:
Using Post Processor Regex Extractor I wrote a regex that returns me several values (already tested it in www.regex101.com and it's working as expected). However, when I do this in Jmeter, I need to provide MatchNo. which in this case will only return to me one certain value. I sort of figured it out that negative digit in this field (Match No) suppose to return all values found. When I use Debug Sampler to find out how many values are returned and to what variables they are assigned, I see a lot of unfamiliar stuff. Please see examples below:
Text where regex to be parsed:
some data here...
"PlanDescription":"DF4-LIB 4224-NNJ"
"PlanDescription":"45U-LIP 2423-NNJ"
"PlanDescription":"PMH-LIB 131-NNJ"
some data here...
As I said earlier, at www.regex101.com I tested this with regex:
\"PlanDescription\":\"([^\"]*)\"
And all needed for me information are correct (with the group 1).
DF4-LIB 4224-NNJ
45U-LIP 2423-NNJ
PMH-LIB 131-NNJ
With the negative number (I tried -1, -2, -3 - same result) at MatchNo. field in Jmeter Regex Extractor field (which Reference Name is Plans) at the Debug Sampler I see the following:
Plans=
Plans_1=DF4-LIB 4224-NNJ
Plans_1_g=1
Plans_1_g0="PlanDescription":"DF4-LIB 4224-NNJ"
Plans_1_g1=DF4-LIB 4224-NNJ
Plans_2=45U-LIP 2423-NNJ
Plans_2_g=1
Plans_2_g0="PlanDescription":"45U-LIP 2423-NNJ"
Plans_2_g1=45U-LIP 2423-NNJ
Plans_3=PMH-LIB 131-NNJ
Plans_3_g=1
Plans_3_g0="PlanDescription":"PMH-LIB 131-NNJ"
Plans_3_g1=PMH-LIB 131-NNJ
I only need at this particular case - Jmeter regex to return 3 values that contain:
DF4-LIB 4224-NNJ
45U-LIP 2423-NNJ
PMH-LIB 131-NNJ
And nothing else. If anybody faced that problem before any help will be appreciated.
Based on output of the Debug Sampler, there's no problem, it's just how RegEx returns the response:
Plans_1,Plans_2,Plans_3 is the actual set of variables you wanted.
There should also be Plans_matchNr which should contain the number of matches (3 in your example). It's important if you loop through them (you will loop from 1 to the value of this variable)
_g sets of variables refer to matching groups per matching instance (3 in your case). Ignore them if you don't care about them. They are always publish, but there's no harm in that.
Once variables are published you can do a number of things:
Use them as ${Plans_1}, ${Plans_2}, ${Plans_3} etc. (as comment above noticed).
Use Plans_... variables in loop: refer to the next variable in the loop as ${__V(Plans_${i})}, where i is a counter with values between 1 and Plans_matchNr
You can also concatenate them into 1 variable using the following simple BeanShell Post-Processor or BeanShell Sampler script:
int count = 0;
String allPlans = "";
// Get number of variables
try {
count = Integer.parseInt(vars.get("Plans_matchNr"));
} catch(NumberFormatException e) {}
// Concatenate them (using space). This could be optimized using StringBuffer of course
for(int i = 1; i <= count; i++) {
allPlans += vars.get("Plans_" + i) + " ";
}
// Save concatenated string into new variable
vars.put("AllPlans", allPlans);
As a result you will have all old variables, plus:
AllPlans=DF4-LIB 4224-NNJ 45U-LIP 2423-NNJ PMH-LIB 131-NNJ

giving a string variable values conditional on another variable

I am using Stata 14. I have US states and corresponding regions as integer.
I want create a string variable that represents the region for each observation.
Currently my code is
gen div_name = "A"
replace div_name = "New England" if div_no == 1
replace div_name = "Middle Atlantic" if div_no == 2
.
.
replace div_name = "Pacific" if div_no == 9
..so it is a really long code.
I was wondering if there is a shorter way to do this where I can automate assigning values rather than manually hard coding them.
You can define value labels in one line with label define and then use decode to create the string variable. See the help for those commands.
If the correspondence was defined in a separate dataset you could use merge. See e.g. this FAQ
There can't be a short-cut here other than typing all the names at some point or exploiting the fact that someone else typed them earlier into a file.
With nine or so labels, typing them yourself is quickest.
Note that you type one statement more than you need, even doing it the long way, as you could start
gen div_name = "New England" if div_no == 1