Checking for same information on user register
Application Type

This is my user registration screen. I need to make so the users cannot register if the same "CPF" is already on the database. The database is updated on the "Salvar" button. The idea is to get all CPF and compare to see if the one being registered already exists. The CPF is an attribute stored in an Entity called "Cidadao"



1-Push the entity cidadao to your server action to filter if there is already a CPF

2- do the filter

3-check if is empty or not. if is empty it means there is not a CPF with the same CPF you are saving to the user. In this way, you end the server action and retrieve a boolean saying that

4- on the client action on your screen you are going to do an if. And if  "ExistSameCPF" you are going to say to the User that there is already the same CPF.


I did so (also some more stuff, dont mind the file is a bit more complex now, the .rar archive is bc of an email stuff i did) and it worked, although, it never lets me register any other CPF: Translates to "this CPF is already in use"


You download the wrong version of what I sent you!

Here it needs to be false. Because if the aggregate is empty is because there is not the same CPF, if is not empty, there is.

So that's why you need to put false, there, because if the aggregate returns not empty, is because there is already someone with the same CPF

And change this for true also

And on the salvar client action swap the connectors, in there put true, because if is exists=true(depending on the last point I said yo you, to put the output true if is not empty the aggregate) is because there is someone with the same CPF

Ps: the screenshots that I took, there is something wrong there, but I fixed the last module version I sent yesterday. I could not change the screenshots because I was not able to edit them again.

So it should be this

Kind regards,


Did it all (i pass the last 20 minutes rechecking, dont think i miss something) but another error showed up:


I think is because of this. You are registering a User, that User will not have an UserId... that's why is giving you that error.

 So what you need to do is... 

1- you are going to pass the local variable that is holding the values for the user that is registering.

2- here you're going to do one condition. Where you check if the user is already registered or not

3- if is not registered, you are going to pass that local variable to the createUser action

4- And then you pass the id created...

5- And there you go, you have everything you need

A last note, I don't know if is going to give you problems, buuut I think is better to encrypt the password of the User like this

Give it a try and let me know

ps: I cannot pass you an OML because my SS is giving a connection error...

Kind regards,


Hello @Cauê Farias Berti,

This is easily solved by adding a unique index constraint on the CPF attribute in the 'Cidadao' entity.

Add a database exception handler as shown below to handle the unique index error gracefully:

Then for e.g. if CPF 123456 was already used to register a user, then the next time it will display the message and not allow using the same CPF twice:

Therefore you no longer have to compare CPF values in the logic.

I have updated the oml with the above changes. Please review.

Hope this helps,





Hi there,

@AJ.I don't fully agree with that solution.

Although the unique index is an extra protection layer (I'd keep it), I would still compare in the logic as well.

This will avoid an unnecessary call to the database server and, most important, you shouldn't handle this as a Database Exception.

As you know, Database Exceptions are raised by the platform when there is an error related to the database management system, which can happen by many other reasons.

This way you will return a business message to the user for every single Database related issue that may occur.

@Cauê Farias Berti if I were you, I'd mix both of these solutions.

I'd put the unique index just to have an extra level of protection (like AJ suggested), but I'd still compare values in the logic as well (like Márcio suggested).

If you want to return a feedback message or place an error message under the input, that's up to your preferences :)

Kind regards,

Rui Barradas

Thank you @Rui Barradas, valid points.

I did totally ignore the perils of relying on a database exception by using a business/ custom message on it. What would have been more appropriate, for the sake of clarity for anyone else following this post, would be to trap the DatabaseException.ExceptionMessage instead.

But that's besides the point. I like your suggestion to combine the logic check and the unique index check!

Best regards,


I aprecciate all the answers! as a beginner, im loving the atention and specialy the patience of the comunity! Im required to build a simple system, as for now, im going with Márcio's approach, since imo it is a more beginner friendly. I aprecciate all the answers tho! Much thanks!!!

I did so, tho it generates the exception every time i register a CPF:

It is doing that because the solution from Aj gives you that answer every time there is a database expectation... That's why is um Pau de dois Bicos :D

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