Your achievements

Level 1

0% to

Level 2

Tip /
Sign in

Sign in to Community

to gain points, level up, and earn exciting badges like the new
Bedrock Mission!

Learn more

View all

Sign in to view all badges

SOLVED

AEM asset metadata delete.

jezwn
Level 4
Level 4

How can I remove dc:description from all the assets? I tried with metadata import by emptying the description column, but it isn't working. 

1 Accepted Solution
lukaszm
Correct answer by
Level 8
Level 8

Hi @jezwn, I am not sure what exactly is your case, and if this is one time activity or something you would like to proceed regularly. Anyway, below you can find simple groovy script that will remove dc:description completely or just erase the value.

import javax.jcr.query.Query
import org.apache.sling.api.resource.ModifiableValueMap

def query = "SELECT * FROM [dam:Asset] AS s WHERE ISDESCENDANTNODE([/content/dam]) and s.[jcr:content/metadata/dc:description] IS NOT NULL"

resourceResolver.findResources(query, Query.JCR_SQL2).each { r ->
    def mvp = r?.getChild("jcr:content/metadata")?.adaptTo(ModifiableValueMap.class)
    if(mvp) {
        // remove dc:description prpeorty
        // mvp.remove("dc:description")
        
        // erase dc:description property value
        mvp.put("dc:description", "")
    }
    resourceResolver.commit()
}

 

View solution in original post

7 Replies
SivaPrasadReddyS
Level 8
Level 8

@jezwn 

Which version of AEM are you using? I tried the same on AEM 6.5.9 and metadata is not updated. Looks it's an issue.

But did you try to do the same using ACS commons? If not, you can try using acs commons asset importer. 

https://adobe-consulting-services.github.io/acs-aem-tools/features/csv-asset-importer/index.html 

 

 

jezwn
Level 4
Level 4

@SivaPrasadReddyS ACS Commons asset importer can't be used to update metadata as the purpose of the tool is to import assets. Feel free to correct me if I'm wrong. And also I needed to have this done for existing assets in DAM.

lukaszm
Correct answer by
Level 8
Level 8

Hi @jezwn, I am not sure what exactly is your case, and if this is one time activity or something you would like to proceed regularly. Anyway, below you can find simple groovy script that will remove dc:description completely or just erase the value.

import javax.jcr.query.Query
import org.apache.sling.api.resource.ModifiableValueMap

def query = "SELECT * FROM [dam:Asset] AS s WHERE ISDESCENDANTNODE([/content/dam]) and s.[jcr:content/metadata/dc:description] IS NOT NULL"

resourceResolver.findResources(query, Query.JCR_SQL2).each { r ->
    def mvp = r?.getChild("jcr:content/metadata")?.adaptTo(ModifiableValueMap.class)
    if(mvp) {
        // remove dc:description prpeorty
        // mvp.remove("dc:description")
        
        // erase dc:description property value
        mvp.put("dc:description", "")
    }
    resourceResolver.commit()
}

 

jezwn
Level 4
Level 4

Thanks @lukaszm Another solution I tried was creating a package of all the metadata nodes under a path, and then update the xml by emptying the dc:description(done using VS Code searching all occurances under the folder), repackaging and installing it.


Nikhil-Kumar
Community Advisor
Community Advisor

@jezwn - Try creating and running your own Groovy/Java/JS script to remove the desired property.

jezwn
Level 4
Level 4

Could you provide an example on how JS Script can be used to update node properties? Thanks!