We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 23
    • 61 Posts
    Hey folks

    i’m sitting here testing over some first plugin code i wrote and i have to save some stuff which doesn’t gives me a problem on existing documents

    on new documents i’m trying to extract the last insertId() with the given modx api function on the event "OnDocFormSave" but everything i get returned is 0, each time i create a new document and save it.

      • 23
      • 61 Posts
      So, i still can’t figure out why getInsertId() isn’t working on "OnDocFormSave" event

      i’m using this sql -> SELECT MAX(id)+1 AS id FROM to determine the next auto-increment for a new document which will be saved, it does the job but i don’t know how this will work under stress situations, means 2 or 3 editors creating new documents
        • 5340
        • 1,624 Posts
        Did you managed to do it. I’m looking for a similar solution
          • 23
          • 61 Posts
          Hey Cipa,

          yes i found out how it works, simply pass $id on your object instance, which will return the next correct highest Key within plugins, when using "OnDocFormSave".

          For example:

          include_once(’some_class.php’);

          new some_class($modx, $id);

          $id will then deliver the next highest Key when firing "OnDocFormSave".



            • 5340
            • 1,624 Posts
            Thanks

            I discovered another one: $e->params[’id’]

            See my solution here