Skip to main content
April 4, 2023
Question

Fetch Foreign Key values in Child Table

  • April 4, 2023
  • 12 replies
  • 0 views

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

12 replies

April 4, 2023

Can you show the code you've written and any supporting screenshots?

April 4, 2023

Here you go... 

Parent Cdt                                                                                               Child Cdt

Database 

April 4, 2023

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.

abhayd3663
April 4, 2023

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

April 13, 2023

You can try to save the output from first write to data store entity to a cdt or any process variable of your choice, then in the script task use the cdt in custom outputs, target as path where you want to store the primary key.