Forum Discussion

detroit's avatar
detroit
Ideator I
7 years ago
Solved

Save item transaction

Hello I have a certain Item1 and on after save event of this item I trigger another item2 (custom item we created) save. In case first one fails the second wont trigger. But the otherway around obv...
  • christopher_gillis's avatar
    7 years ago

    Hello,

    This kind of transaction rollback exists inherently inside of Aras Innovator. For example, if I run the method code below, the transaction that created the Part will be rolled back because of the error thrown at the end.

    Innovator inn = this.getInnovator();

    // Create a new part
    Item part = inn.newItem("Part", "add");
    part.setProperty("item_number", "My Part 1");
    part.apply();
    // The part now exists in the database

    // But the transaction is rolled back when this error is thrown
    // If we check for the part after running this method, it will not exist
    return inn.newError("Can not add part");

    This kind of transaction rolls back for any number of nested server calls. For instance, if I call another method which successfully creates an item and then throw an error, the item created in the called method is still part of the same transaction and will be rolled back when the error is thrown from the calling method. Similarly, if an error is thrown in a server event, any and all transactions associated with the triggering item or any other server events will be rolled back.

    I'd suggest taking a look at your existing approach to see if some of this logic could be migrated from the client to the server. We typically recommend keeping this kind of logic inside of a server event so that the same functionality will be run whether the item is saved through the client or an external application.

    Chris