# Problem with CALL apoc.do.when

**URL:** https://community.neo4j.com/t/problem-with-call-apoc-do-when/15706
**Category:** Cypher
**Created:** [March 12, 2020, 9:52am UTC](https://community.neo4j.com/t/problem-with-call-apoc-do-when/15706 "2020-03-12T09:52:00Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![madiskou](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/madiskou/32/16515_2.png) [@madiskou](https://community.neo4j.com/u/madiskou)
#### Post date: [March 12, 2020, 9:52am UTC](https://community.neo4j.com/t/problem-with-call-apoc-do-when/15706/1 "2020-03-12T09:52:00Z")

</div>

Hello,  
I am new to neo4j cypher, and i try to construct a graph with multiple use of the apoc.do.when, but i have a problem, the error is :

```auto
Expected parameter(s): CT, vm_src, vm_dest, app_src, app_dest

```

And my cypher script is :

```auto
LOAD CSV WITH HEADERS FROM "file:///input.csv" AS CT

//Create vm
MERGE (vm_src:VM {name : CT.hostname_source})
MERGE (vm_dest:VM {name : CT.hostname_dest})

WITH vm_src, vm_dest

// create app with label Unknown_appli	
CALL apoc.do.when($CT.source_appli_name = "unknown_appli", 
'MERGE (app_src:App:Unknown_appli{name: "CT.hostname_source"}) RETURN app_src',
'MERGE (app_src:App{name:"CT.source_appli_name"}) RETURN app_src',
{CT:$CT}) YIELD value
WITH value.app_src as app_src

CALL apoc.do.when($CT.appli_name_dest = "unknown_appli" , 
'MERGE (app_dest:App:Unknown_appli{name: "CT.hostname_dest"}) RETURN app_dest',
'MERGE (app_dest:App{name: "CT.appli_name_dest"}) RETURN app_dest',
{CT:$CT}) YIELD value
WITH value.app_dest as app_dest

//create calls relations
CALL apoc.do.when($CT.direction = "IN" AND $vm_src.name <> $vm_dest.name , 
		'MERGE ($vm_dest)-[:CALLS]->($vm_src) RETURN $vm_dest', '',
        {CT:$CT,vm_src:$vm_src, vm_dest:$vm_dest}) YIELD value
WITH value as ignored

CALL apoc.do.when($CT.direction = "IN" AND $app_src.name <> $app_dest.name, 
		'MERGE (app_dest)-[:CALLS]->(app_src) RETURN app_dest', '', 
        {CT:$CT,app_src:$app_src, app_dest:$app_dest}) YIELD value
WITH value as ignored1
		  

CALL apoc.do.when($CT.direction = "OUT" AND $vm_src.name <> $vm_dest.name, 
		'MERGE ($vm_src)-[:CALLS]->($vm_dest) RETURN $vm_src', '', 
        {CT:$CT,vm_src:$vm_src,vm_dest:$vm_dest}) YIELD value
WITH value as ignored2

CALL apoc.do.when($CT.direction = "OUT" AND $app_src.name <> $app_dest.name , 
		'MERGE (app_src)-[:CALLS]->(app_dest) RETURN app_src', '', 
        {CT:$CT,app_src:$app_src,app_dest:$app_dest}) YIELD value
WITH value as ignored3

//create child relations
MERGE (app_src)-[:CONTAINS]->(vm_src)
MERGE (app_dest)-[:CONTAINS]->(vm_dest)

```

Any help please ?

---

<div class="post-metadata">

### Author: ![MuddyBootsCode](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/muddybootscode/32/10330_2.png) [@MuddyBootsCode](https://community.neo4j.com/u/MuddyBootsCode)
#### Post date: [March 12, 2020, 10:40am UTC](https://community.neo4j.com/t/problem-with-call-apoc-do-when/15706/2 "2020-03-12T10:40:13Z")

</div>

Your cypher is expecting that anything with a $ in front of it is a supplied parameter or variable. The error is telling you that you're not actually supplying those parameters. If you're loading from a csv take a look at this example and how the variables are declared from the CSV row [Importing CSV Data into Neo4j - Developer Guides](https://neo4j.com/developer/guide-import-csv/).

---

<div class="post-metadata">

### Author: ![madiskou](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/madiskou/32/16515_2.png) [@madiskou](https://community.neo4j.com/u/madiskou)
#### Post date: [March 12, 2020, 1:55pm UTC](https://community.neo4j.com/t/problem-with-call-apoc-do-when/15706/3 "2020-03-12T13:55:00Z")

</div>

I didn't find how to use variables in th doc?

---

<div class="post-metadata">

### Author: ![intouch\_vivek](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/intouch_vivek/32/4097_2.png) [@intouch\_vivek](https://community.neo4j.com/u/intouch_vivek)
#### Post date: [March 12, 2020, 3:39pm UTC](https://community.neo4j.com/t/problem-with-call-apoc-do-when/15706/4 "2020-03-12T15:39:34Z")

</div>

> [@madiskou](#):
>
> d i try to construct a graph with multiple use of the apoc.do.when, but i have a problem, the error is :

Try below

> **[Parameters - Cypher Manual](https://neo4j.com/docs/cypher-manual/current/syntax/parameters/)**
>
> This section describes parameterized querying.

IF you need to pass variable name in the query with value of name as Madiskou, then try as  
:param name=\>'Madiskou';  
Match(n:Person{Name:$name})  
Return n

Above query will find all the Node of Label Person have name as Madiskou.  
Also If possible then rename the topic

---

<div class="post-metadata">

### Author: ![MuddyBootsCode](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/muddybootscode/32/10330_2.png) [@MuddyBootsCode](https://community.neo4j.com/u/MuddyBootsCode)
#### Post date: [March 12, 2020, 5:45pm UTC](https://community.neo4j.com/t/problem-with-call-apoc-do-when/15706/5 "2020-03-12T17:45:46Z")

</div>

The example in the docs show's how to use property from a row as a variable like:

```auto
LOAD CSV WITH HEADERS FROM 'file:///data.csv' AS row
WITH row WHERE row.Company IS NOT NULL
MERGE (c:Company {companyId: row.Id})

```

In your case it would be like you've show in your code:

```auto
 CT.<your variable here> 

```

I'm not sure why you're using $.

---

<div class="post-metadata">

### Author: ![andrew\_bowman](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/andrew_bowman/32/73_2.png) [@andrew\_bowman](https://community.neo4j.com/u/andrew_bowman)
#### Post date: [March 12, 2020, 6:19pm UTC](https://community.neo4j.com/t/problem-with-call-apoc-do-when/15706/6 "2020-03-12T18:19:20Z")

</div>

`CT` is in scope from your LOAD\_CSV, at least for awhile.

One big critical problem here is that you're eliminating variables from scope via your WITH clauses. WITH restricts what is in scope, so as soon as you reach `WITH vm_src, vm_dest`, `CT` is no longer in scope and you can't use it further in your query. If you need to use a variable later on, you must include it in your WITH clause otherwise it's out of scope.

You have similar problems with your other WITH clauses.

As was mentioned by others, you don't need to use parameter syntax here, use just `CT` instead of `$CT`.
