Secondary keys Unique

I created a new table in navision, with a primaryKey like (A,B)

My question is, how can I make unique the secondary key B.

AB is Unique, but B must be unique too.

How can I do That?

May I know why do you need that?

And what problem are you facing while creating key with B?

Unfortunately, in the NAV table designer there is no property to enforce uniqueness of secondary keys. You will have to program OnInsert and OnModify to take care of that.

Do you know any object where I can have it for exemple?

Thanks

No I don’t, sorry

Its a very common requirement. If you search the forum you will find this asked a lot.

Actually, I misunderstood the question…

In first my table should be validate with a double key, fields (Vendor Nº+XPTO).

So, when I have a record A+B and a Record C+B its possible

But know, on this case, when I have already a record A+B in my table, trying to insert C+B I will get one error message informinn that field XPTO=B alreadi exist and is related with another vendor Nº. This is what I want to validade.

thanks

There are many ways, and it depends on how many records you have. The main issue is actually to determine when the record is inserted. If you have delayed insert on or not.

As a starting point though, on the insert record you want code something like:

Add a key on field 2.

MyRec.reset;

myrec.setcurrentkey(field 2

Myrec.setrange(field 2, rec.field 2

myrec.setfilter(field 1,’<>%1’,rec.field 1

if myrec.findfirst then

message(the value in field 2 is not unique

This solution was a big Help. Thanks

Instead of message I want insist with user to insert a <> field, until that ,he can not exit, How can I do That

If I Modify one old record, the same validation must be done.

I copy the same instruction to Modify Triger but no result :frowning:

If you are modifying the Primary Key field then it will trigger OnRename trigger not onmodify…

The code snippet I gave because this is not standard anywhere in Navision, so I wanted to get you started, but understanding of the basics of Navision is something that every developer needs to learn. Go to a basic Navision training class or speak to a senior developer in you organization about learning the basics.

I would consider just making B the primary key and having A,B as a secondary key. Uniqueness of B will also guarantee uniqueness of A,B.

Really, how?