Given a folder path how to get its folder_id

Given a folder path returned from

$folderpath = $user.psoFolders.getParentFolderPath($sys.item.guid)

how do I get its folder_id that can be used by


which requires input parameter of folder_id?

Thanks, Hua

I find the easiest way to get a folder id (assuming you want the id of the folder the item in question is in) is to retreive it from the parameters being sent:


If trying to get the folder id from some other folder and all you have is the path as the string: $folderpath, this should do it (NB. PSO toolkit required):


You have to be careful with this code. $sys.params.get(“sys_folderid”).0 will pull the folder id from the url parameters. This will work on publish and will work when previewing an item from a folder, but will error if previewing from a view or search result as the actual folder id is not passed in this case.

$user.psoFolders.getParentFolderPath($sys.item.guid) is slightly different does not look at the folder id of the current item but looks for the content id of the location if finds in the foldercache to see which folder(s) the item is in. The problem with this is if the item is in more than one folder (e.g. copy as link) it will always return the first result which may not be the expected result when previewing or publishing from the second folder.

The best way of doing this is using.

$folderpath = $user.psoFolders.getParentFolderPath($sys.assemblyItem)

This will use the folder id passed in the url if it is available, e.g. it will be different if the same item is previewed or published in folder A, or folder B. Otherwise it uses the same mechanism the Navigation uses to find the Navon (which will pick the first result but this is just preview from search or views).

If you want to check out these methods you can go here.