CreateOrUpdate action - what should ID be for create?
Question
Application Type
Reactive
Service Studio Version
11.14.11 (Build 59394)
Platform Version
11.15.0 (Build 34858)

I'm a newbie with Outsystems and I have to start by saying that I've never seen a product so woefully documented by a company that makes money by licensing their product. 2-minute long videos are not documentation. The use cases in these videos are too simplistic to be useful. My needs aren't too complex, but I've spend 2-3 days on figuring out how to do straightforward things. Its time Outsystems hires a few tech writers who will write real documentation.

My frustrations aside, here is my situation:

The system defined user object isn't enough for me. I need a few extra attributes in User table. So I created an AppUser entity whose ID's type is User.Identifier (I had to learn this trick to create a 1:1 relationship between two entities by some community video on YouTube - no obvious documentation for this either!). In the AppUser entity, I have added my app specific user attributes.

Now I need a list of AppUsers and corresponding Details page to create or update AppUsers. I dragged AppUser onto the MainFlow screen. AppUsers' attributes alone aren't enough - I need the User object's fields as well - so I dragged these onto the screen as well. If I just publish as is and try to create a new AppUser (I thought the system will be smart enough to internally create a User first before trying to create an AppUser as it is a 1:1 relationship but no such luck). It creates just the AppUser and fails because I'm assuming the 1:1 relationship has created a constraint that User.Identifier should exist and it fails (again - no documentation to be found on constraints auto-created). 

The autogenerated SaveDetail action associated with the AppUserDetail screen seems to call AppUserCreateOrUpdate with an AppUser object as parameter. I'm guessing I have to create a User myself in this action first, get its ID and set AppUser's ID as that value before creating the AppUser object.

My question is this: Can I blindly call the CreateOrUpdateUser action with the GerAppUserById(AppUserID).User object and expect it to do the right thing? Either create or update based on if the object exists or not? How does it know? Does the method assume that an ID of 0 means it is a create? Is there a better way to do this?

EDIT: I just tried doing just this. Called CreateOrUpdateUser action with the GetAppUserById(AppUserID).User object as the parameter. It seems to have created a new user object in the database and assigned a new unique ID. But when I assign CreateOrUpdateUser.id to AppUser.id, I see that it is still 0. What am I doing wrong? Why is CreateOrUpdateUser creating a new user but not returning the ID?

Hi Ryan Johnson,


when you create a new record then you set UserId to NullIdentifire().

and when update user record u shoud set userId to currentuserId from user Aggregate.

Create.jpg

Hi @Ryan Johnson when you are going to create a data during navigation you need to provide the UserId as mandatory parameter and and set the value to NULL because it will create automatically and then insert your desired data


    hope this will help.

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