How is your experience with the OutSystems Community?
24
Views
4
Comments
Error executing query foreign key constraint
Application Type
Reactive
Service Studio Version
11.55.92 (Build 65269)
Platform Version
11.42.1 (Build 47790)

After submitting form in outsystems 11 it give insert error foreign key input parameter is structure where it includes entity B. The form has a dropdown which is static entity with no AutoNumber it has 2 values let's call it A. There are 2 modules Core and Main module.

 There is a form inside a popup in main module which submits Dropdown as well as inputs after save on pop up it throws Error executing query foreign key constraint. 

The error is definitely coming from CREATEORUPDATEENTITYB which is a normal entity and has foreign key of A and is caught under All exceptions handler. 

Upon checking on logs, it mentions INSERT statement conflicted with the foreign key constraint where [entityB].[foreignkeyA] upon checking an expression for foreign key value on UI it shows 1 whereas the input parameter value of foreign key in structure says 0. Wondering what could be done to solve the issue. The static entity has both records.

2026-01-28 16-57-48
Mihai Melencu
Champion

Hi @Saish Bhende ,

I think there is a mismatch. You probably are using the wrong variable somewhere. Check the input / dropdown bound variable, it should point to the same variable you pass to the save action.

It would be helpful if you attach your OML or a sample OML.

UserImage.jpg
Dhananjay Sharma

It seems that value you are using on a screen is not mapped correctly while passing as input to core module. If you can attach oml file then it will help in finding the root cause.

2026-05-10 20-22-56
Rashid Al-Aamri

Hi Saish,

The log already tells you the cause: the value that reaches CreateOrUpdateEntityB is 0, which is NullIdentifier(). There is no record of static entity A with Id 0, so the database rejects the insert. Both static records existing doesn't matter, because the 1 you see on screen never makes it into the structure. Building on what Mihai and Dhananjay said, these are the usual places where the value gets lost with a popup form:

1. The popup is a Block
If the form lives in a Block shown inside the Popup, the Block's input parameter is a copy of the parent's variable. The dropdown updates the copy inside the Block, but the parent screen still holds the original record with A = 0 and sends that to the save action. Fix: either do the save from inside the Block, or trigger an Event from the Block (e.g. OnSave with the record as a parameter) and have the parent assign it before calling the server action.

2. The Dropdown is bound to a different variable
Check the Dropdown's Variable property. If it points to a separate local variable (e.g. SelectedAId) instead of MyStructure.EntityB.AId, you need an explicit Assign MyStructure.EntityB.AId = SelectedAId before the save. The expression showing 1 is probably reading that local variable, not the structure.

3. The structure is rebuilt or reset before the save
Look for an Assign of the whole record (e.g. from an aggregate's Current, or a OnParametersChanged/OnAfterFetch that re-runs when the popup opens) that overwrites the record after the user picks the value.

How to pinpoint it in 2 minutes
Put a breakpoint on the client action that calls the Core server action, open the popup, pick a value and click Save. In the debugger, inspect the exact variable you pass as the input parameter. If AId is already 0 there, the problem is on the UI side (cases 1 to 3). If it's 1 there but 0 inside the Core action, check the input parameter mapping in the server action call.

Prevent it next time
Set the dropdown as Mandatory, and in the server action add a guard If EntityB.AId = NullIdentifier() that raises a User Exception with a clear message. That way a missing selection shows "Please choose an A" instead of a database foreign key error in the logs.

Hope this helps!

2026-08-05 13-00-31
Ramesh Gangasagare

Hi @Saish Bhende 

I would first check the dropdown's variable binding and the record passed to "CreateOrUpdateEntityB".


Since the dropdown shows "1" but the input structure contains "0", the selected value might not be assigned to the record being saved. If the popup uses a Block, also check whether the updated record is passed correctly to the parent screen.


Try debugging the value just before calling the Core server action and again at the beginning of that action. This should help identify where the value is getting lost.


Hope this helps!


Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.