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.
-
☆ A M B ☆
- 24,524 Posts
That depends... can you post a link to your snippet?
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.
I can get the parent’s id of a created document by $_REQUEST[’pid’]. This solved my problem, thank you!