Escalate any user rights to admin
Normally web apps run under the web app user (which is anonymous and has very little to zero rights by default) and for certain operations you would need to require to grant additional access, or even grant full admin. To grant full admin for web app user is not solution to go with.
Instead I have found that you can temporary escalate any user rights and perform any admin operation that is required and then deescalate back.
The magic function I am talkin about is called logonEscalation you can find mentions of it in the JSSP pages. I have found that the same function works in web apps (they are subset of JSSP ) and what is really surprising it works as well inside the workflow JavaScript activity.
//escalate right to user var logonEscalationCtx = logonEscalation("admin"); //do you admin stuff with current user //return back to your actual user logonWithContext(logonEscalationCtx);