Forum Discussion

lpignedoli's avatar
lpignedoli
Ideator I
8 years ago

Disable Add relationship

Hi all, I should disable the ability to create a new relationship when an Item is in a certain state. For example: I have an Item Document with an relation to Item File. When the user create a new document (state document = New)  he can create a new relationship with an Item File. If the Document is promoted to another state (Check) the user can only modified the property of Document but he can't modify a relationship (add, remove, edit). I found more example to hide a Tab Relationship, but i want to show this tab in Readonly mode.   Thanks

4 Replies

  • Hello,

    An easier solution than disabling the new button would be to add an onBeforeNew Client Event to the relationship's ItemType with code similar to the sample below.

    var parState = parent.thisItem.getProperty("state");
    if (parState === "YOUR_STATE") {
    aras.AlertError("Cannot add Document File while parent is in " + parState + " state.");
    return false;
    }
    Please note that while this Client Event will block a user from adding items through the web client, it will not prevent additional relationships from being added directly through AML. To prevent this, it would be best to also add an onBeforeAdd Server Event with similar C# or VB code. Chris ________________________________ Christopher Gillis Aras Labs Software Engineer
  • I have another question. If I also want to disable the delete an existing relationship when the state of Parent aren't "New"? Thanks    
  • Hello, For your use case, it may be desirable to programmatically set the permissions of these relationship items in an onAfterPromote server event on the parent itemtype. This way, you use the built-in aras permission model to disable new relationships from being added or deleted based on the parent's life cycle state. While the post below doesn't cover this exact use case, it does provide an example on how to programmatically update an item's permissions which you can modify to fit your needs. http://community.aras.com/en/knowledgebase/permissions-based-item-property-values/ Chris _____________________________________ Christopher Gillis Aras Labs Software Engineer