CycleOp - Monday, June 6, 2011 11:41 AM:
Hi,
I have a relation between ItemTypes "A" and "B". I have a server side method on ItemType "A" which checks if any relations to "B" exist.
virgilm - Monday, June 6, 2011 5:28 PM:
Hello Sagi
I don't understand what you are trying to do. If you are creating item A there can not be any relations to it yet . The relationship ties two ID's together - source_id to related_id. Since A does not yet exist , it does not have an ID so no relationship to it can exist. After you create it , it will then have an ID, but since it is a new ID it again can not exist in a current relationship table unless you are creating in a grid - then the item and the relationship are created at the same time, but again since the item's ID is new, the relationship is new also.
If both items already exist and then you try to add a relationship, you could check to see if a relationship exists before adding the relationship ( using the onBeforeAdd event of the relationship) and error out the method if it does so a second relationship is not created.
Virgil.
Brian - Tuesday, June 7, 2011 8:21 AM:
Hi Sagi,
You can check the incoming AML in the onBeforeAdd/onBeforeUpdate to see if it contains any relationships between A and B rather than looking in the database for already saved relationships.
If you are creating a new "A" (assuming this is the Parent in the relationship) then there can't already be a relationship to "B" as Virgil said. You can look for the "isNew" attribute to work out if you are in the onBeforeAdd or use different methods in the two triggers.
If you are in onBeforeUpdate then it is possible that the relationship already exists but your user should be able to see this in the grid as they create the relationship themselves. If you are creating a new relationship rather than having the user do it then knowing if you are in onBeforeAdd or onBeforeUpdate will be important to you.
Cheers,
Brian.