cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

How to pass result value from one statement to another

I have the below code where it runs multiple statements, First Statement should return a result which is used by Second Statement , it is a call from android app .

return session.writeTransaction(wrte=>{
    let r : any

    if(context.auth){

  //This Statement returns ID of the node

      wrte.run('MATCH (p:Person{identity:{identity}}) CREATE (p)-[po:POST]->(a:Post{post:{post},userName:{userName}}) RETURN ID(a)', 
      {identity: context.auth.uid, post: data.post, userName: context.auth.token.name })

    }
   return r as neo4j.v1.StatementResult

  })

 //how to get the ID from the Last Statement

  .then((val) =>  session.readTransaction(read => {
    console.log(val.records[0].get(0))
    return read.run('MATCH  (p:Post) WHERE id(p) = {any} RETURN p',{any: val.records[0].get(0)})
  }))

.then(result => {
    session.close();      
    driver.close()
    console.log(result)
    var singleRecord = result.records[0]
    var dat = singleRecord.get(0)

    if(result.records[0] == null){

      return  null

    } else {
      return {

        "post": dat.properties.post,
        "userName":dat.properties.userName,
    }

    }

  }).catch(error => {
    session.close()
    console.log(error)
    driver.close()
    throw new functions.https.HttpsError(error,"some error");
  })
});

console.log(val.records[0].get(0)) returns undefined, how to properly pass results and how to retreive ID?

3 REPLIES 3

Why do you have this in two separate statements? You could easily just return p from the first statement.

i tried everything but it returns undefined value, may i am doing something wrong?

I just forgot to return the transaction, now it works.