Preventing Duplicate ID

Contains tips for configurators working with Aware IM
Post Reply
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Preventing Duplicate ID

Post by vinsnash »

I've set a rule:

IF EXISTS MYOBJ WHERE (MYOBJ.ID = THISMYOBJ.ID) THEN REPORT ERROR 'DUPLICATE ID DETECTED'

When creating a new object this reports the error every time regardless of the ID entered.

Is there another way? The ID attribute is indexed.

Thanks
pbrad
Posts: 781
Joined: Mon Jul 17, 2006 11:03 pm
Location: Ontario, Canada

Post by pbrad »

Hi,

Your rule will only find itself, not duplicates. You need to exclude the current object, not limit your EXIST statement specifically to the current object. If you study the rule that is loaded by default in every business space, you will see what you need to do:

If EXISTS SystemUser WHERE (SystemUser.LoginName=ThisRegularUser.LoginName AND SystemUser.ID<>ThisRegularUser.ID) Then
REPORT ERROR 'User with this login name already exists. Please choose a different name'

cheers,
Pete
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

Makes sense to me!

Thanks much
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

I think I spoke too soon. I don't quite follow how to exclude the current object in this situation.

MEMBERS
Members.ID (text alphanumeric 8 characters)
Members.Name
Members.Address
Members.Phone
etc.

Any number of regular users can create new MEMBERS and I need to prevent the entry of duplicate Members.ID. I don't want Members.ID to be changed and create a duplicate either. Names can and will be duplicated i.e. "Smith, John".

Hope you can clear this up for me.

Thanks again
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

I'm confused about your use of the attribute ID.

I thought that ID was reserved for AwareIM use. You won't see it in the list of attributes in a BO, but you will see if listed if you create a Query of the BO.

Are you talking about trying to control this ID or some other ID?
Tom - V8.8 build 3137 - MySql / PostGres
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

Sorry, that's just a typo. The attribute is Members.IDCode, not the AwareIM ID.

Thanks
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

Using Pete's example as a model, try:

If EXISTS Members WHERE (Members.IDCode=ThisMembers.IDCode AND Members.IDCode<>ThisMembers.IDCode) Then
REPORT ERROR 'Member with this ID Code already exists. Please choose a different ID Code'
Tom - V8.8 build 3137 - MySql / PostGres
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

I tried it but it allows duplicates. I don't really understand the logic. It seems contradictory. If a MEMBERS object exists where (a Members.IDCode = the Members.IDCode being entered and Members.IDCode not equal the Members.IDCode being entered) can't ever be true.
tford
Posts: 4238
Joined: Sat Mar 10, 2007 6:44 pm

Post by tford »

oops -- too many ID type attributes floating around. My bad.

This WILL work:

If EXISTS Members WHERE (Members.IDCode=ThisMembers.IDCode AND Members.ID<>ThisMembers.ID)
Then
REPORT ERROR 'Member with this ID Code already exists. Please choose a different ID Code'
Tom - V8.8 build 3137 - MySql / PostGres
vinsnash
Posts: 415
Joined: Sun Oct 07, 2007 4:58 pm

Post by vinsnash »

Excellent! Now I see the use for the AwareIM ID :D

Many thanks!
Post Reply