Can't create instance of an entity
Application Type
Traditional Web
Platform Version
11.12.2 (Build 30755)

Im' trying to create instance of an entity using a custom Server Action but it doesn't work. When I insert these values directly into database this objects is created. When I use debugger I always get SQL error when creating any type of object (I get this even with server action I'm sure works 100%)

SQL Error text:

The INSERT statement conflicted with the FOREIGN KEY constraint "OSFRK_OSUSR_49U_CONTRACTORS_FILES_OSSYS_USER_CREATEDBY". The conflict occurred in database "PNUJEY013", table "dbo.ossys_User", column 'ID'.

The statement has been terminated. 

AddFileContractors_Files

 System.Data.SqlClient.SqlException: The INSERT statement conflicted with the FOREIGN KEY constraint "OSFRK_OSUSR_49U_CONTRACTORS_FILES_OSSYS_USER_CREATEDBY". The conflict occurred in database "PNUJEY013", table "dbo.ossys_User", column 'ID'.


The statement has been terminated.


Also project file attached, hope someone helps me understand why my Server Action isn't working. Function is Portal/Create/SaveOnClick

ComplianceControl.oap

Hi Konstantin,

first off, you probably shared the wrong module, there is nothing in the Portal flow, there's no SaveOnClick in any of your screens, there's no entity called ContractorsFile...

When you say you are 100% sure the server action works, what do you mean, what is the name of that server action, can you share it.

If you are 100%, then the error must be caused by the way you call the server action, probably not passing in the UserId that is creating this instance.

Because that's most likely what is going on, you are trying to create a record with NullIdentifier as CreatedBy, but this is probably a mandatory field.

Dorine

Here's the right file sorry.

I'm using GetUserId() for CreatedBy.

AddFileContractors_Files is Server Action that work fine, CreateContractor is broken.

ComplianceControlv0.oml


I see that your Create screen has anonymous check box on.  

So are you maybe testing this screen without being logged in ?  In that case GetUserId will be NullIdentifier.  If i must be possible for anonymous user to use that screen, you should make CreatedBy not mandatory, i think.

Dorine

I've removed the Anonymous checkbox and it still doesn't work for me

ComplianceControlv0.oml

Champion

Hi , 

As I can see in your  Request table , createdby (data type - user identifier ) is a attribute that is foreign key and it is mandatory.  You must supply a value  to createdby during insert operation and that value (user identifier) must reside in user table.

Your uploaded oml have certain dependencies and I am not able to find saveonclick server action. Please reupload it.

Here's the right oml file, sorry. For createdBy I'm using GetUserId() function

ComplianceControlv0.oml

Champion

As I can see , Your Create screen is Anonymous. So, How can you get User id. Please make it registered and check it again. It should work fine. GetUserId() will give user id only when user is registered. When Screen is anonymous it should have Null value.


Cheers

I've checked off Anonymous and it still doesn't work for me?

ComplianceControlv0.oml

Champion

As I can see, In your module there is no existing Layout followed during development. You are trying to getUserId but there is no mechanism is for user login. 


Champion

At OnException there should be a separate flow for Security Exception. So that when unregistered user try to access your screen it should redirect to your login page after login user should access your create screen and perform any operation. 

At OnException there is only flow one flow. That Is AllExceptions that is capable to handle all. But You should make separate flow for Security Exception otherwise no use of anonymous or registered role at screen. Somewhat similar to below image.


You can take help by create different app with existing outsystems (LayoutTopMenu) layout. At Common flow you can see OnException where you can find how it handled. You can check updated oml too.

Hope this help.


ComplianceControlv0updated.oml

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