The P4 Groovy documentation says:
To allow P4Groovy code to be executed uncheck the 'Use Groovy Sandbox' checkbox under the Pipeline script.
However, the "Pipeline script from SCM" option does not currently support disabling the Groovy Sandbox.
Happily, when I tried P4 Groovy anyway, I simply had to whitelist
method org.jenkinsci.plugins.p4.groovy.P4Groovy run java.lang.String java.lang.String when prompted, and it appears to be operating without issues.
I didn't try the inline pipeline script setup, and there's no record in the git history of why this restriction is listed in the documentation.
So worth retesting whatever issues were seen before, and hopefully that means the documentation can be updated to remove the restriction.