How to Delete DAM asset which is having specific property in AEM using servelt or groovy script? | Community
Skip to main content
Level 2
February 11, 2021
Solved

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

  • February 11, 2021
  • 1 reply
  • 2308 views

Hi Team,

 

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

 

 

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by raj_mandalapu

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();*/
}

}

1 reply

raj_mandalapu
raj_mandalapuAccepted solution
Level 7
February 11, 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();*/
}

}