on 03-21-2014 2:19 AM
Hi,
I want to make 5 primary keys in my BO. I used AlternativeKey option but it has the limitation of must-have different data types. And they are not working as same as Primary Keys in Database.
So, please help.
Any help is appreciated.
Regards.
May T.
Hi,
Is there any code or logic that can solve the compound problems.?
Thanks, everyone.
Best Regards,
May T.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi May T,
You can define one element as alternative key and other 5 five elements as non-alternative elements in your BO
[AlternativeKey]element myKey:ID;
element keyA:ID;
element KeyC:ID;
element KeyB:ID;
element KeyD:ID;
element KeyE:ID;
Then in BeforeSave you can concatenate all 5 non-alternative fields and assign it into alternative field
import ABSL;
if(this.KeyA.IsInitial() && this.KeyB.IsInitial()&& this.KeyC.IsInitial() && this.KeyD.IsInitial() && this.KeyE.IsInitial())
{
var a = this.KeyA.Concatenate(this.KeyB).Concatenate(this.KeyC).....so on
this.myKey = a;
}
You can always identify your instance using alternative key, but using other ID there would be chance you will receive more than one instance.
Hope this help
Sunil
Hi,
I am not an expert either. So still not sure about the Alternative Key. But as Fernando Giroleti said,
2 or more Alternative Keys are not working like a compound PK. So I use some coding in BeforeSave not to save the same data again.It kind of works . But the problem is in Edit. The logic becomes silly in Edit.
Thanks for discussion,
Regards
May T
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
I might be wrong, but an Alternative Key is not a Primary Key (as per its name...). The PK is not exposed for us. If you set 2 or more Alternative Keys, it won't work like a Compound PK.
As I said, I am not 100% sure about what I am saying, and would be great to have some more experts here to talk about.
That's a good discussion,
Best regards,
Fernando
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi May,
Unfortunately, that is the limitation in cloud. You cannot have Alternative Keys of same Data Type and you cannot expect them to behave like a normal primary key in on premise DB.
Here you should make a filed alternative key if that particular column is unique not the set of columns.
More over we had serious issues where our custom object had 3 Alternative Keys and Retrive does not work properly on all the fields. When we search on second field it used to try to fetch the record based on first field. When we raised it to SAP they had told it is picking Alphabetically first one and they are working on it to fix the problem. But as of now it is not yet fixed.
So my suggestion would be use Alternative Key on multiple fields if it is really required, if possible redesign your BO.
Regards
Vinod
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.