We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 630
    • 39 Posts
    How can I determine which id a freshly created document will get once saved? Or at least, how do I get the parent’s id as shown under "Resource parent"? The getParent/getPageInfo api calls don’t work as they need a known id passed, that’s why I’m asking. Can neither use the ability of the mysql database driver to tell the next virgin primary key id, as this could be grasped by another manager session that is running simultaneously (want to program multi-user-safely).

    As by now, my TaggoNG snippet -presented in another thread- can’t properly perform the action mgr_GatherTags to return input options for template variable ’TaggoNG_Tags’, as it does not know where the new resource will be created. That’s why the document must be saved before the editor is able to select the tags, which is ugly.


    -- agilero.
      • 28042 ☆ A M B ☆
      • 24,524 Posts
      That depends... can you post a link to your snippet?
        Studying MODX in the desert - http://sottwell.com
        Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
        Join the Slack Community - http://modx.org
        • 630
        • 39 Posts
          • 3749
          • 24,544 Posts
          Since the document doesn’t have an ID until saved, you need to get its id from the name (pagetitle) *after* saving it. Unfortunately, AFAIK, there’s no API function to get a document by name. You’ll have to query the DB directly and check the modx_site_content table for the row with that "pagetitle" and retrieve the ID. The parent’s ID should be in the "parent" field of the same record.

          See the MODx DbAPI. http://wiki.modxcms.com/index.php/API:DBAPI

          Maybe someone else knows an easier way.

            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 630
            • 39 Posts
            I can get the parent’s id of a created document by $_REQUEST[’pid’]. This solved my problem, thank you!