logo

Executing a script under a specific user

In 3.0 scripts are run on behalf of the user who belongs to the swimlane where the previously executed process activity is located. Starting from 3.0.6 all the scripts by default are run on behalf of the user who is responsible for the process instance, but it is also possible to run scripts under the name of a selected user. To select a user, use the RunByUser method.

Script with PublicAPI

Note
Documentation on PublicAPI is available here
Attention
The script below is relevant for ELMA 3.8 to 3.12.1 inclusive.
var user = PublicAPI.Portal.Security.User.LoadByLogin("admin"); 
PublicAPI.Services.Security.RunByUser(user, () =>
{
    //code; 
});

Script without PublicAPI

Required namespaces:
using EleWise.ELMA.Security;
using EleWise.ELMA.Services;

Script text:

var securityService = Locator.GetService<ISecurityService>();
securityService.RunByUser(user, () => {
 //code; 
});

The code in brackets will be executed under the name of the specified.