Hi Community Team,
Here, I'm using two Cdt's One parent table (Emoloyee Details) and one child table (Comments).
I'm calling primary key in the parent table into the child table to fetch the values in the Child table. I'm getting NULL instead of primary key of parent Cdt. Please help me out how to configure this error?
Child PK Parent FK
Comments_ID Employee_ID
1 NULL
2 NULL
3 NULL
4 NULL
5 NULL
Discussion posts and replies are publicly visible
Can you show the code you've written and any supporting screenshots?
Here you go...
Parent Cdt Child Cdt
Database
You have to use two seperate writeToDatastore entity smart service to write the data with foreign key concept. In the first WritetoDatastoreEntity insert the value to parent Table and save the inserted value to the same variable in the output of that node and in the second writetodatastoreentity use the parent variable primary key to store it as a foreign key. With that, you will be able to add parent table id to child table.
I am not able to get it how can I use use the parent variable primary key to store it as a foreign key. Can you please explain it
Here, is my Process model
In script task use parent CDT pv to get primary key and save it in the id field of Child CDT
For eg:
In the first datastore entity go to output of the data tab and in that you will be able to see storedValue and in the configuaration map it with the same variable which you are using to insert and than in the script task use the expression which Sanchit give and use the child variable as a input to the second datastoreEntity node.
The Employee table should have the FK ref. to Comments table. Not the other way round. Comments table don't need any FK reference.
Employee Table
---------------------
id - PK
empId
empName
commentsId - FK to Comments.id
Still giving me an null value in the CDT
Check the Comment ID in the Comment table is referenced as a foreign key in the employee table in your database and CDT.