62
Views
5
Comments
Solved
CreateOrUpdate Record with Same Indexes Value Does Not Work

Hi, I have set FirstName and LastName attributes as index, and I have a form that performs action CreateOrUpdate. I thought if I entered existing first name and last name, it will automatically update the record that has the name with new details, but it shows this error instead. So I would like to ask why do CreateOrUpdate fails when index is implemented? And what is the solution to it?


2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

a unique index is not the same as a primary key.

In Outsystems, you can only have a primary key on a single attribute (usually called id), and the CreateOrUpdate or the Update or the Delete entity actions use this attribute to know which one you want to act on.

If you want get at an existing record by other unique (combination of) attribute (like for example when having to work with a unique value form an external system as only input), you'll have to do an aggregate reading on this other index first, then use that found record / id to act on it.

But if at all possible, use the real primary key as the way of identifying what record you are working on, that's what it is there for.

Dorine

2023-02-20 05-20-57
Nam Nguyen

Hi Max Chia,
You have this error because you set the index FirstName and LastName is unique which means duplicate is not allowed. In your case, (Jerome , Wilde) is existed in the database so that if you insert for the second time, you will get this error.


Please set the unique to No to solve this issue.


Cheers,
Nam


UserImage.jpg
Max Chia

Hi, what if I want the index to be unique? 

2021-09-06 15-09-53
Dorine Boudry
 
MVP
Solution

a unique index is not the same as a primary key.

In Outsystems, you can only have a primary key on a single attribute (usually called id), and the CreateOrUpdate or the Update or the Delete entity actions use this attribute to know which one you want to act on.

If you want get at an existing record by other unique (combination of) attribute (like for example when having to work with a unique value form an external system as only input), you'll have to do an aggregate reading on this other index first, then use that found record / id to act on it.

But if at all possible, use the real primary key as the way of identifying what record you are working on, that's what it is there for.

Dorine

2023-01-26 16-03-24
Ana Agostinho

Hello Max Chia, 


To complement the comment provided by @Dorine Boudry you have also a nice and well given definition provided by @Eduardo Jauch on the following post with some examples: 

Moreover, I would recommend you to go to the following documentation to get a better understanding:

Best regards, 

Ana


UserImage.jpg
Max Chia

Thank you for the explanation, it cleared my mind!

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