How to Delete DAM asset which is having specific property in AEM using servelt or groovy script?

Avatar

Avatar

chandrareddy

Avatar

chandrareddy

chandrareddy

11-02-2021

Hi Team,

 

Can someone suggest how to delete DAM documents which is having particular property either servlet or groovy script or any other methods?

 

 

Accepted Solutions (1)

Accepted Solutions (1)

Avatar

Avatar

raj_mandalapu

MVP

Avatar

raj_mandalapu

MVP

raj_mandalapu
MVP

11-02-2021

I have taken groovy script code from the below article and modified according to your reuirement, but did not test this code, you need to test this in the local before running into production or QA.

https://hashimkhan.in/aem-adobecq5-code-templates/groovy-script/

 

def predicates = [path: "/content/dam/geometrixx", type: "dam:Asset", "orderby.index": "true", "orderby.sort": "desc"]
def query = createQuery(predicates)
query.hitsPerPage = 500
def result = query.result
println "${result.totalMatches} hits, execution time = ${result.executionTime}s\n--"

result.hits.each { hit ->
def path=hit.node.path
String nodePath = node.path;
if (hit.node.hasProperty(propName)) {
count ++;
println 'deleting--'+nodePath ;
node.remove();
/* Save this session if you are sure the correct nodes are being deleted. Once the session is saved the nodes couldn't be retrieved back.
*session.save();*/
}

}

Answers (0)