Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.
SOLVED

AEM asset metadata delete.

Avatar

Level 6

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

Avatar

Correct answer by
Community Advisor

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

Avatar

Community Advisor

@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 

 

 

Avatar

Level 6

@Siva_Sogalapalli 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.

Avatar

Employee Advisor

Why do you want to remove this property?

Avatar

Correct answer by
Community Advisor

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()
}

 

Avatar

Level 6

Thanks @lukasz-m 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.


Avatar

Community Advisor

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

Avatar

Level 6

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