2 Replies Latest reply on Aug 2, 2014 10:05 PM by N Varma

    How to find flex asset parent before asset save completes


      Hello All,


      I want to create a hook that would allow us to block an asset from saving successfully, based on the below logic:


      Assets can go in any folders(just another parent definition called Folder) but then we need to restrict certain assets from going to certain folders. For that to happen we need to know the parent of the asset before the save actually happens (data written to DB).


      I know that I can manipulate the attributes of an asset in a PreUpdate element using asset-get/set tags example:


      <asset:get name="theCurrentAsset" field="title" output="assetTitleVariable"/>

      <asset:Set name="theCurrentAsset" field="title" value="new title value"/>


      But the problem is that asset-* tags doesnt give me the parent information like the parent assetid,  assettype which i need to uniquely identify a parent.


      Does anyone know of any tag or any way I can get this information out?


      Thanks in advance..



        • 1. Re: How to find flex asset parent before asset save completes
          Pedro Gutierrez



          A way to do that is using the following tag:




          The tag reference for it is here:




          An example of my own based on the sample provided in the tag reference is the following where I retrieve the id for a content child of type Content_C via its cid and then I look for its parent (content type Content_P):


          String cid = ics.GetVar("cid");
          <searchstate:create name="mainSS" op="or"/>
          <!-- add constraint to get parents for the specified child in cid -->
          <searchstate:addhasdescendantconstraint name="mainSS" assetid='<%=cid %>' assettype="Content_C"  bucket="ss2" />
          <!-- results of the list are parents for the assest specified in cid -->
          <assetset:setsearchedassets name="myassetset" constraint="mainSS" assettypes="Content_P"/>
          <!-- transform assetset to list to retrieve id -->
          <assetset:getassetlist name="myassetset" listvarname="aslist"/>
          <!-- loop through list and render parent id's -->
          <ics:listloop listname="aslist">
          parent id: <ics:listget fieldname="assetid" listname="aslist"/>


          Hope it helps.


          Best regards,


          • 2. Re: How to find flex asset parent before asset save completes
            N Varma



            As Pedro suggested, that is one way to get the Parent Id.


            2nd way is to use FieldCopier on Parent asset - Copy the asset id in some custom attribute say "ParentId" and after saving any Parent asset, this ParentId will contain asset id of the parent asset which will be available to child asset using assetset:getattributevalue tag wherein you can set immediateOnly="false" to get this "ParentId" value and perform whatever operation you want to.


            I hope this helps.