Desktop Neo4j (3.4.7)
Fair warning: I'm very new to Cypher, Apoc, and Neo4J in general
I'm building a neo4j database for our service delivery, and as such I've already pulled in items like:
Employee, Customer, Contacts, and used apoc.load.jdbc to query and create some nodes/relationships. Those nodes have the relevant IDs so I can match them in further MATCH/MERGE commands.
Now I'm trying to do something a bit more complex, and having some trouble working this out. I want to import our tickets, and at the same time create relationships to the nodes (that already exist) for contact, employee, and company. I KNOW a ticket will be tied to a manager (employee) and MOST tickets will also have a contact and a company associated, but it is possible they wont.
So I wanted to create the ticket, create a [:MANAGED_BY] relationship to the employee who holds the ticket, and then if available match to the company (and make a relationship) and same for the customer contact. I assumed I would use WITH to perform additional matches, and this query runs without error, but it only creates the (Ticket) node (and the t.Manager and that relationship), but fails to add the t.Account, t.Contact or either of those relationships. Is there a better approach I should be taking here? Thanks for reading.
PS - I'm not sure if this post belongs in the APOC or the CYPHER category... what is proper etiquette regarding cross-posting for these forums?
call apoc.load.jdbc('jdbc:sqlserver://;servername=mysqlserver;databaseName=CommitCache;user=neo4jreader;password=somepassword',' SELECT TICKETNO,CARDID,CONTACTID,WORKERID,STATUS,SOURCE,ASSETRECID,DUEDATETIME from [CommitCache].[dbo].[Tickets]')
yield row
MATCH (e:Crmemployee {acctrecid:row.WORKERID})
MERGE (t:Ticket {TicketNumber:row.TICKETNO})
ON CREATE
set t.Manager = e.name
MERGE (t)-[:MANAGED_BY]->(e)
WITH t,row
MATCH (a:Company {acctrecid:row.CARDID}),(t)
set t.Account = a.name
MERGE (t)-[:TICKET_CLIENT]->(a)
with t,row
MATCH (c:Contact {acctrecid:row.CONTACTID}),(t)
set t.Contact=c.name
MERGE (t)-[:OPENED_FOR]->(c)
Return t,c