Forum Discussion

Fflur's avatar
Fflur
Ideator I
2 years ago

Is there an easy way to run code after a change/creation transaction finished?

Hello, 

I need to send a created/ changed item to another service. I have some code that just needs the ID of an Item, it then retrieves it from the database and sends it to the other service.

The problem I am facing is that, I can't find a way to run said code after the item is saved to the database. If I try to run my code in the onAfterUpdate Event it fails because it tries to retrive the item with the new ID before the transaction finsihed.

So basically what I am looking for is something like an onAfterTransaction Event.

Would appreciate any ideas on how to approach this problem.

Thanks!

3 Replies

  • Hi Flur! It sounds like the onAfterUpdate event should do the trick, though you may want to include an onAfterAdd event if you need to run your logic for newly created items as well. 

    I have a couple questions to help troubleshoot the issue you’re seeing:

    • What’s the error message you’re seeing?
    • Is the context item versionable?
    • Can you share your onAfterUpdate method code? At least the part that shows how you’re trying to get the data to send to the other system? 
    • Fflur's avatar
      Fflur
      Ideator I

      Hi Eli, thanks for the quick reply!

      - When I pressed save or done on an Item I used to get a null error message, (now I dont see any error in Aras but the save still fails/ gets aborted)

      - I'm not quite sure what that means, but when I save an item, a versioning attribute is incremented and I can also create new revisions of the item

      - My Code:
          var id = this.getID();
          var type = this.getType();
          MyDll.MyFunction(id, type);
          return this;

      The basic idea is that I get the updated id of the changed item and feed them into my custom function. Inside of MyFunction I do an async AML request against Aras <AML><Item type="type" action="get" where="[Item].id='id'" /></AML> and then push the result to a different service. This works fine if I test it with a static id but if I try to use this.getID() the changed item does not get found and the AML returns null as result.

      • Fflur's avatar
        Fflur
        Ideator I

        Small update, I found the function "CCO.DB.InnDatabase.CommitTransaction();" and if I call this before MyFunction everything works like I expected. Is this fine or is there a better way to do this?