Endpoint Management User Group (Osterreich, Schweiz, Deutschland)

Expand all | Collapse all

How to export an item with all its parent folder-hierarchy?

Jump to Best Answer
  • 1.  How to export an item with all its parent folder-hierarchy?

    Broadcom Employee
    Posted 08-07-2014 02:30 AM

    Hello, community,

    I have just got an interesting question from a large customer.

    Ever time they create an item in CMS7.5 (like a software policy) they want to export this into a standalone xml-file for backup purposes and to be able to import this item also in their test- end QA-environments.

    The challenge here is to make sure that the folder-hierarchy to the exported item should also be exported to make sure that the folders have the same structure and same GUIDs on all environments.

    Unluckily the APIs to export a folder will also export the full conent of the folder which is absolutely not what they want.

    And if they want to create their own folder-item XMLs based on the folder-attributes there is no "productGuid" attribute for the folder-items but this is needed to import a folder-XML.

    Does someone have a clever idea how to get this problem solved???

    I made a couple of tests and it turns out that you can import a self-created folder-XML that just includes the name, guid, class and the 000-GUID as a fake-productGuid, but I am not sure if this will be supported? AFAIK if an item-import works fine without errors it will have support.

    Greetings,

    Carsten

     



  • 2.  RE: How to export an item with all its parent folder-hierarchy?

    Broadcom Employee
    Posted 08-07-2014 03:25 AM

    Hi Everybody

     

     



  • 3.  RE: How to export an item with all its parent folder-hierarchy?

    Posted 08-07-2014 03:24 AM

    What if you export the folder and just remove the <children> part from the XML (or replace it with <children/>)?
    That would make one XML per folder but should be easy to implement with vbs or powershell.

    Advanced:

    If you just export the root folder and remove all children that do not have classGuid="{f1e8956a-a158-487f-8185-4c3b492734e7}" that should just keep the complete folder structure.



  • 4.  RE: How to export an item with all its parent folder-hierarchy?
    Best Answer

    Broadcom Employee
    Posted 08-08-2014 11:38 AM

    Many thanks for all good repsonses and suggestions here.

    We have solved it in that way that we use an ASDK-script to lookup the parentFolderGuid in a loop until the attribute of the folder includes "ReadOnly". This will avoid the problem that we continue this up to the root folders where even the simple GetItemByGuid()-command will respond with nearly the whole database content in an XML-file.

    BTW: It would be great if there would be an ItemExists()-command in the ASDK. This would be really benficial especially for PresentationFolders with lots of subfolders etc. Have someone discovered a similar function in one of the existing *.asmx-files?

    Thanks for the support.

     

     



  • 5.  RE: How to export an item with all its parent folder-hierarchy?

    Broadcom Employee
    Posted 08-07-2014 06:37 AM

    Hi Carsten!

    My understanding is that you want to achieve the following:

     

    Folder A Contains Folder B

    Folder B contains Folder C

    Folder B contains Folder D

    Folder B contains Item X

    Folder C contans item Y

     

    If you want to export Y, then you want to see A, B, C, Y, but not X, D - correct ?

    The simple answer is NO there is NO such API.

    You'll need to write some C# code to throw away things like D, X from the Parent folder export XML

     

    If you just export the root folder and remove all children that do not get into the set of the ancestors of Y

    Altiris.NS.ItemManagement.Item

    public static GuidCollection GetAncestors(Guid itemGuid, bool includeSelf)

    then you are done.

     

    I did not quirte understand what was the concern here and what  "based on folder attributes" mean

    And if they want to create their own folder-item XMLs based on the folder-attributes there is no "productGuid" attribute for the folder-items but this is needed to import a folder-XML

    Yes, productGuid is must have for EACH  item being imported (except the native config installation mechanism which enforces the productGuid automatiocally for all the items).

    If one is  not sure which produict guid to use - just use NS product guid

    d0e33520-c160-11d2-8612-00104b74a9df

     

    Regards

    Arthur

     

     

     

     



  • 6.  RE: How to export an item with all its parent folder-hierarchy?

    Broadcom Employee
    Posted 08-08-2014 03:51 AM

    Hi, Carsten:

    This is an interesting point, but I'm afraid it is not as simple as it seems.

    I had the same idea, to have the same objects between my different environments (dev, pre-prod and prod) two years ago. One option I considered was to "export" the folder as I created it, with no objects created inside it, and then export every single object I created, so that I could "import" the empty folder in another environment (keeping the same GUID), and then "import" the objects I needed into it (one by one).

    After importing the objects I needed into their folders, I could check in the console that things were Ok, but when I had a look at the logs in the server, I discovered that a new error was appearing, related to a user not available in the database.

     

    After spending a lot of time investigating this error, I realized that the user missing had the same GUID that the user I used to create the objects in their first environment.

    If you read the XML from an object, you can see an attribute named "ParentGuid" (I don't have a console in front of me, so this name may not be exactly the same) which references to the GUID of the folder where the object is placed (this value is replaced if you import the object under another folder). This is true also for folders: a folder is always placed into another folder :)

    This happens because when you export an object, the security applied to this object also is included in the XML, and when you import the XML, the part of the security is also imported: if the security groups or users don't exist in the server where you import the object, you get no message about this in the import process.

    I tried to export an user into an XML, but I couldn't find a way to do it...

    So, the only solution I found for fixing this issue was replacing the GUID of the users/groups into the security part of the XML of the object with the users/groups from the new environment BEFORE importing the object in the new environment.

     

    This will apply also if you have to reinstall a SMP and you have to create again the users/security groups, as they will have a new GUID.