Syntax for using variable-item-string in when statement

What’s the right way of using jinja2 in when statement .

I basically have a condition to check if something like below exists in stdout of perious results.

When :
_ ’ {{ var1 }}-{{ var2}}-{{ item }}-{{ var3 }} in prev_results.stdout’

Jinja isn’t allowed in when.

The above variables are appended with hyphen and item value to generate the actual string .
So whats the right syntax to use that.
Kindly assist

I got this working.

When :
  - " var + '-'+var2 +'-'+item "

I have another problem now.

Please assist.

I have inventory variables like below :

[Grp1]
Host1 dblist='["sar","Cor",...]
Host2 dblist='["db1","DB2","db3",...]'

#dblist for every host is huge like some 20 items.

Now for every hostgroup I have group variables file under group_vars dir

Example of Grp1.yml under griup_vars dir

Cat Grp1.yml

App_attr:
  
  - attr : "varname"
    attrval : "str"
    attrtype : "string"

  - attr : "secname"
    attrval : "DB"
    attrtype : "typing"

  - .
    .
    .
Etc
Same like above keys n diff values

In one of my task I need to access both inventory host list variable dblist and group variables App_attr

Name : access both of them.
Command : myscript {{ item.O }}-{{ inventory_hostname }} --appname {{ item.1.attr }} --appval {{ item.1.attrval }} --apptype {{ item.1.attrtype }}

With_items:
   - "{{ dblist }}"
   - "{{ App_atrr }}"

I'm getting error.
Dict object has no element 1.

Looks like App_attr is not parsed properly. What's the right way to pass it.
Please suggest