Forum Discussion

conner_davis's avatar
conner_davis
Ideator I
2 years ago
Solved

Server Method working when given a GUID, but not when using this

Hello,

When I run this server method from the method itself and use a GUID to get the Item I want to update the method works fine, but when I change it from a GUID to = this; and run it from the  Item Type on the server events "OnBeforeUpdate" it crashes the whole server and the server has to be restarted.

// Item KSAAsses = inn.getItemById("smc_KSA_Assessment","2956D6CFB25949D39985FF112F2395FA");
Item KSAAsses = this;

Has anyone ever ran into something similar?

I can post more code if needed.

Thank you for your help!

  • Thank you alaxala,

    Do you have any recommendations on where I could run this as an event then to avoid the recursive call?

    or would going a route of getting a property to key off of like string ksaNumber = this.getProperty("_ksa_number","") not be a recursive action? or because that call is still using this it will be recursive?

  • alaxala's avatar
    alaxala
    2 years ago

    In context of OnBeforeUpdate method you can change "this" any way, but you can't use this.apply() or perform any actions that will result in an this item being written to the database because it will trigger OnBeforeUpdate again.

    When you inside OnBeforeUpdate you inside some upper "apply" already. So just change properties of "this" and return this. All your changes will be applied calling code.

3 Replies

  • If you applying changes of the "this" item any way inside the OnBeforeUpdate event, your method just called recursively.

    • conner_davis's avatar
      conner_davis
      Ideator I

      Thank you alaxala,

      Do you have any recommendations on where I could run this as an event then to avoid the recursive call?

      or would going a route of getting a property to key off of like string ksaNumber = this.getProperty("_ksa_number","") not be a recursive action? or because that call is still using this it will be recursive?

      • alaxala's avatar
        alaxala
        Ideator I

        In context of OnBeforeUpdate method you can change "this" any way, but you can't use this.apply() or perform any actions that will result in an this item being written to the database because it will trigger OnBeforeUpdate again.

        When you inside OnBeforeUpdate you inside some upper "apply" already. So just change properties of "this" and return this. All your changes will be applied calling code.