AEM asset metadata delete. | Community
Skip to main content
jezwn
Level 5
Dec 3, 2021 1:03 PM UTC
Solved

AEM asset metadata delete.

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. 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
lukasz-m
lukasz-mAccepted solution
New Participant
Dec 4, 2021 5:07 PM UTC

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

 

7 replies

Nikhil-Kumar
New Participant
Dec 6, 2021 7:00 AM UTC

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

Translate
jezwn
jezwnAuthor
Level 5
Dec 6, 2021 2:04 PM UTC

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

Translate
lukasz-m
lukasz-mAccepted solution
New Participant
Dec 4, 2021 5:07 PM UTC

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

 

Translate
jezwn
jezwnAuthor
Level 5
Dec 6, 2021 2:10 PM UTC

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.


Translate
joerghoh
Employee
Dec 4, 2021 3:11 PM UTC

Why do you want to remove this property?

Translate
Siva_Sogalapalli
New Participant
Dec 3, 2021 2:48 PM UTC

@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 

 

 

Translate
jezwn
jezwnAuthor
Level 5
Dec 6, 2021 2:13 PM UTC

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

Translate