Foreign Key

  

I have two simple tables

Employee that contains two attributes: ID, Name

Location that contains three attributes: ID, City, EmployeesID

Requirement

I will like to flow from the Employees detail screen to the Location screen - easily achieved. 

On the Employee Screen, I enter the Name and Save. - This takes me to the Location detail screen

In the Location screen, I will like the ID of the last entry in the Employees table to appear in the EmployeeID field as the default value and inserted into the Location Entity as the EmployeeID when I hit save

Solution

Hi,

have you tried to use Input Parameter on the Location Screen? 

1. Add an input parameter on the Location Screen

2. Call the Location screen from Employee Screen, fill in the input parameter with newly created Employee ID 

3. Assign the input parameter as Employee ID before saving the Location record

hope that helps.

Solution

Hi Olu,

From your tables looks like your users can have multiple locations. If this shouldn't be the case than LocationId should be on employee table and not the other way around.

In case of multiple locations I would recommend you to have a list of locations in the employee detail screen

In case of just 1 location you have 2 options or you have the fields to create the location or if you create the locations in other place just add a combo box to select a location.

Regards,

Marcelo

Hi Marcelo, 

Thanks for your response. 

What I am trying to do is one-to- one relationship. 

User enters personal detail - User Screen

User Enters Address e.g location - City Screen

Then I join User's address to User by the User ID, hence the User ID is in the address table. 

I have managed to get this working now after following Imelda's response above. 

Although I had some Foreign Key constraint messages which i then solved using the comments from a different thread see link

https://www.outsystems.com/forums/discussion/34412/the-insert-statement-conflicted-with-the-foreign-key-constraint/

It is all good. I now understand how to pass the identifier of an Entity to another Entity as a foreign key. Thanks to you all. 



Imelda Nugraha wrote:

Hi,

have you tried to use Input Parameter on the Location Screen? 

1. Add an input parameter on the Location Screen

2. Call the Location screen from Employee Screen, fill in the input parameter with newly created Employee ID 

3. Assign the input parameter as Employee ID before saving the Location record

hope that helps.

Thanks for the the response and useful advice. Although providing a little more detail for beginners like us will be much appreciated. Nonetheless from what you suggested I was able to make some progress using the debugger to ensure the assignment of the input parameter, but not that straight forward I must say. 


Anyway I was able to perform the assignment but then go a foreign key constraint issue, so I had to do more reaserch and found this useful link that explained more about the input paramer and how the assignment should work. 

https://www.outsystems.com/forums/discussion/34412/the-insert-statement-conflicted-with-the-foreign-key-constraint/

It is all good now. Thanks


Hi Olu Oshodi,


Glad to hear you can solved the issue. 

Also thank you for the feedback. I will try to explain better next time.

Hi Imelda. 

Thanks - I guess you provided the necessary direction. Much appreciated.