Hi Team,
we are in AEMasCS, we are trying the update a Text content across our global pages, for that we are using sling pipes,i downloaded the package of groovy script from below git hub Github link and installed in my local. here is my groovy script,when i tried to execute the script im getting user permisson issue though groovy-console-system-user have all access please find below screenshot. Kindly help on this.
groovyscript
=====
import org.apache.sling.api.resource.ResourceResolver
import org.apache.sling.api.resource.ResourceResolverFactory
import org.apache.sling.pipes.Plumber
import org.apache.sling.pipes.PipeBindings
// Get the ResourceResolverFactory service
def resourceResolverFactory = getService(ResourceResolverFactory)
def plumber = getService("org.apache.sling.pipes.Plumber");
// Define the path to the content you want to update
def contentPath = "/content/wknd"
// Define the text to find and replace
def findText = "helloworld"
def replaceText = "updated helloworld"
Map<String, Object> param = new HashMap<>()
param.put(ResourceResolverFactory.SUBSERVICE, "sling-pipes-user")
ResourceResolver resourceResolver = resourceResolverFactory.getServiceResourceResolver(param)
try {
// Create a new pipe
println resourceResolver.getUserID()
def pipe = plumber.newPipe(resourceResolver)
.echo(contentPath) // Start at the content path
.xpath("/jcr:root${contentPath}//element(*, nt:base)[jcr:contains(., '${findText}')]") // Find nodes containing the text
.write("jcr:title", replaceText) // Replace the text in the jcr:title property
.run()
// Execute the pipe
plumber.execute(resourceResolver, pipe, null)
println "Text replacement completed successfully."
} catch (Exception e) {
e.printStackTrace()
println "An error occurred: ${e.message}"
} finally {
resourceResolver.close()
}
Topics help categorize Community content and increase your ability to discover relevant content.
Views
Replies
Total Likes
hi @rajat168 ,
Check if that user is having the required permission. Also cross check if there is any typo in user name.
You may have a look osgi config section of https://satyamblogs.medium.com/groovy-script-in-adobe-experience-manager-aem-d8071223627d
Thanks
@rajat168 Script execution access is allowed only to specific user groups. Be default it is the administrators group. make sure the current logged in user is part of the administrators group and you should be able to execute the script. If you want to have some other user group that should be allowed access to groovy script execution, then you can update the groovy console OSGI config property - Script execution allowed groups.
Hope this helps.
Hi @Harwinder-singh , i have added groovy-console-system-user into administrator group as well. but still have same issue.
@rajat168 Can you add the user that you are using to log in to your local instance to the administrators group? The script is being executed by the logged in user here. If you are logging in with admin/admin , then just add the Administrator user to the administrators group. Due to some weird reason the admin user is not added to the administrators group by default.
Also update the Script execution allowed groups property to administrators as well.
Hi @arunpatidar , im able to use currect user session but still facing same issue.PFB,
import org.apache.sling.api.resource.ResourceResolver
import org.apache.sling.api.resource.ResourceResolverFactory
import org.apache.sling.pipes.Plumber
import org.apache.sling.pipes.PipeBindings
def resourceResolver = getService("org.apache.sling.api.resource.ResourceResolverFactory").getServiceResourceResolver(null)
def plumber = getService("org.apache.sling.pipes.Plumber")
def contentPath = "/content/wknd"
// Define the text to find and replace
def findText = "helloworld"
def replaceText = "updated helloworld"
try {
// Create a new pipe
println "current User ::${resourceResolver.getUserID()}"
def pipe = plumber.newPipe(resourceResolver)
.echo(contentPath) // Start at the content path
.xpath("/jcr:root${contentPath}//element(*, nt:unstructured)[jcr:contains(., '${findText}')]") // Find nodes containing the text
.write("jcr:title", replaceText) // Replace the text in the jcr:title property
.run()
// Execute the pipe
plumber.execute(resourceResolver, pipe, null)
println "Text replacement completed successfully."
} catch (Exception e) {
e.printStackTrace()
println "An error occurred: ${e.message}"
} finally {
resourceResolver.close()
}
It is available, if does not work then, please check alternate at https://github.com/orbinson/aem-groovy-console
Hi @rajat168
Please use already available resourceResolver (currentUser).
Don't create explicit resourceResolver for groovy service user(This user might not have permission on content).
explicit resourceResolver for groovy service user
resourceResolver (currentUser)
available bindings
Hi @arunpatidar , kindly please gothrough my above screenshot, i have used exisiting user account. also im currently using the same groovy console version which is not compatable with aemascs.
Did you find the suggestions from users helpful? Please let us know if you require more information. Otherwise, please mark the answer as correct for posterity. If you've discovered a solution yourself, we would appreciate it if you could share it with the community. Thank you!
Views
Replies
Total Likes
Views
Likes
Replies
Views
Likes
Replies
Views
Likes
Replies