Setting related Item to null relationship

How do I set related Item to null relationship on the onAfterEvent of the relationship ?

Parents
  • To answer your question,

    There are multiple OnAfterEvents, you would need to pick which event to use e.g. OnAfterAdd/OnAfterUpdate.  On after events work with the Item after it is saved to the server, you have to retrieve the Item, check for the property, edit it and set the property to null then apply the result.

    Because using an onAfter event will process the Item After it has been saved to the server, editing the item can cause a second onAfter event to fire, so you need to be careful not to end up in a loop.

    It may be better (if possible) to use an OnBefore event, e.g. onBeforeAdd/OnBeforeUpdate. An onBefore event works with the context item before it is saved to the server. This means you only need to edit the context item (this for c#, or me for vb) to remove the property (or set the property to null) within the method, before the result it is saved to the server (you do not need to apply the context item).

    The 3rd way would be to use javascript to remove the related item on the client before the information is passed to the server.

    So the order is:

    JavaScript (Client side - before the information is passed to the server - result will be passed to the server)
    OnBefore (Server side -before the information is saved to the server - result will be saved)
    OnAfter (Server Side - After the information has been saved to the server - result will be returned to the calling method/action)

    Hope this helps,

    Many thanks,
    Martin

Reply
  • To answer your question,

    There are multiple OnAfterEvents, you would need to pick which event to use e.g. OnAfterAdd/OnAfterUpdate.  On after events work with the Item after it is saved to the server, you have to retrieve the Item, check for the property, edit it and set the property to null then apply the result.

    Because using an onAfter event will process the Item After it has been saved to the server, editing the item can cause a second onAfter event to fire, so you need to be careful not to end up in a loop.

    It may be better (if possible) to use an OnBefore event, e.g. onBeforeAdd/OnBeforeUpdate. An onBefore event works with the context item before it is saved to the server. This means you only need to edit the context item (this for c#, or me for vb) to remove the property (or set the property to null) within the method, before the result it is saved to the server (you do not need to apply the context item).

    The 3rd way would be to use javascript to remove the related item on the client before the information is passed to the server.

    So the order is:

    JavaScript (Client side - before the information is passed to the server - result will be passed to the server)
    OnBefore (Server side -before the information is saved to the server - result will be saved)
    OnAfter (Server Side - After the information has been saved to the server - result will be returned to the calling method/action)

    Hope this helps,

    Many thanks,
    Martin

Children
No Data