agarcia
I'm new here

Fail to create a PageFolder programmatically

Jump to solution

I'm trying to create a PageFolder programmatically from a Script in ServerManager but the execution fails.

This is the part of the script where I try to create the folder (inspired by other answers in this forum):

StoreElementAgent storeElementAgent = context.requireSpecialist(StoreElementAgent.TYPE);

IDProvider parentFolder = storeElementAgent.loadStoreElement("content", PageFolder.UID_TYPE, true);

folder = parentFolder.createFolder("NewFolder"); // This is line 20, referred by the error message

folder.save();

And I get the following exception:

ERROR 26.07.2019 12:44:23.713{dNR=} (de.espirit.firstspirit.server.scheduler.ScriptTaskExecutor): error during script execution : de.espirit.firstspirit.access.script.ExecutionException: null : at Line: 20 : in file: inline evaluation of: ``__execute() { import de.espirit.firstspirit.access.AccessUtil; import de.espirit . . . '' : parentFolder .createFolder ( "NewFolder" )

Called from method: __execute

Target exception: java.lang.NullPointerException: Null Pointer in Method Invocation

at line 20

de.espirit.firstspirit.access.script.ExecutionException: null : at Line: 20 : in file: inline evaluation of: ``__execute() { import de.espirit.firstspirit.access.AccessUtil; import de.espirit . . . '' : parentFolder .createFolder ( "NewFolder" )

Called from method: __execute

Target exception: java.lang.NullPointerException: Null Pointer in Method Invocation

at line 20

at de.espirit.firstspirit.server.script.BeanshellScriptEngine$BeanshellExecutable.execute(BeanshellScriptEngine.java:109)

at de.espirit.firstspirit.common.ScriptUtil.execute(ScriptUtil.java:106)

at de.espirit.firstspirit.server.scheduler.ScriptTaskExecutor.run(ScriptTaskExecutor.java:134)

at de.espirit.firstspirit.server.scheduler.ScheduleManagerImpl$TaskCallable.executeLocal(ScheduleManagerImpl.java:2285)

at de.espirit.firstspirit.server.scheduler.ScheduleManagerImpl$TaskCallable.executeLocal(ScheduleManagerImpl.java:2268)

at de.espirit.firstspirit.server.scheduler.ScheduleManagerImpl$TaskCallable.call(ScheduleManagerImpl.java:2188)

at de.espirit.firstspirit.server.ExecutionManagerImpl$ExtendedCallable.call(ExecutionManagerImpl.java:590)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at de.espirit.common.util.BoundedExecutorService$RunnableWrapper.run(BoundedExecutorService.java:436)

at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)

at java.util.concurrent.FutureTask.run(FutureTask.java:266)

at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)

at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)

at java.lang.Thread.run(Thread.java:748)

at de.espirit.common.util.SuspendableThread.run(SuspendableThread.java:56)

Caused by: java.lang.NullPointerException: Null Pointer in Method Invocation

at bsh.Name.invokeMethod(Name.java:844)

at bsh.BSHMethodInvocation.eval(BSHMethodInvocation.java:75)

at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:102)

at bsh.BSHPrimaryExpression.eval(BSHPrimaryExpression.java:47)

at bsh.BSHAssignment.eval(BSHAssignment.java:77)

at bsh.BSHBlock.evalBlock(BSHBlock.java:130)

at bsh.BSHBlock.eval(BSHBlock.java:80)

at bsh.BshMethod.invokeImpl(BshMethod.java:371)

at bsh.BshMethod.invoke(BshMethod.java:267)

at bsh.BshMethod.invoke(BshMethod.java:170)

at bsh.PreparsedScript.invoke(PreparsedScript.java:66)

at de.espirit.firstspirit.server.script.BeanshellScriptEngine$BeanshellExecutable.execute(BeanshellScriptEngine.java:100)

... 14 more

I tried to create a Page in content store instead and I had the same problem.

I configured my credentials in the Properties section of the script task in ServerManager.

I'm Administrator of the project and the server.

I assume I'm having a writing permissions problem but I can't figure out how to solve it.

Is there anything pending to configure to have write permission in scripts?

PS: Sorry if the question has already been asked but it's difficult for me to use the search in German.

1 Solution

Accepted Solutions
seegers
Returning Observer

Hi Andres,

I am not sure which FS Version you are using, but I can give some pointers anyway:

- The "StoreElementAgent" is part of the develop-api not the stable access-api, so it might not be accessible in your version

- Did you check if you actually have a valid "StoreElementAgent" or null?

- Did you check if you actually have a valid "parentFolder" or null?

- The function to create a new folder is here "createPageFolder" (and differs for other folder types).

Hope this helps,

René

View solution in original post

2 Replies
seegers
Returning Observer

Hi Andres,

I am not sure which FS Version you are using, but I can give some pointers anyway:

- The "StoreElementAgent" is part of the develop-api not the stable access-api, so it might not be accessible in your version

- Did you check if you actually have a valid "StoreElementAgent" or null?

- Did you check if you actually have a valid "parentFolder" or null?

- The function to create a new folder is here "createPageFolder" (and differs for other folder types).

Hope this helps,

René

Hi seegers

It turns out the last one was the key.

StoreElementAgent & parentFolder were valid objects.

Now it's working with:

folder = parentFolder.createPageFolder("NewFolder");

There was a mistake in the method name, as you pointed out.

However, it was still failing.

Another problem seemed to be that the parent folder wasn't released.

And without:

folder.save();

Thanks for your suggestions and help!,

Andres.

0 Kudos