Expand my Community achievements bar.

SOLVED

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

Avatar

Level 2

Hi Team,

 

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

 

 

1 Accepted Solution

Avatar

Correct answer by
Level 8

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

}

View solution in original post

1 Reply

Avatar

Correct answer by
Level 8

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

}