web
You’re offline. This is a read only version of the page.
close
Skip to main content
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Execute a batch with different user than submitting user

(0) ShareShare
ReportReport
Posted on by

Hi,

I want to execute a batch with different user than it schedule, basically I want to run all the batches using a service account rather individual users who scheduled the job. Also this job has to run in server

I have modified the runsImpersonated as below but this is not executing the job by specified account while I check in batch job history. Is there any way I can achieve the same

public boolean runsImpersonated()

{

    RunAsPermission perm;

    UserId          runAsUser;

    SysUserInfo     userInfo;

    ;

    runAsUser = 'xxx’;

    perm = new RunAsPermission(runAsUser);

    perm.assert();

 

    runas(runAsUser,classnum(XXXX),'run');

    return true;

}

*This post is locked for comments

I have the same question (0)
  • Tim Schofield Profile Picture
    on at
    Re: Execute a batch with different user than submitting user

    Or you could just create a user like 'AXBATCH' and use it to create and run all your batch jobs.

  • Community Member Profile Picture
    on at
    Re: Execute a batch with different user than submitting user

    Creating AXBATCH is fine , however I don't want to give this particualr use for RDP access.

    Basically I have to login in X user and rns the batch by Y user

  • jaestevan Profile Picture
    1,719 on at
    Re: Execute a batch with different user than submitting user

    This doesn't work because this method is not intended to do that. This method is only usefull to return true or false for the Batch to be executed at server or client layer. No more.

    And this is this way because the batch is not executed in that method, so you can't impersonate from there. If you want to impersonate from code (if you don't have any better solution) you have to impersonate the execution of the batch itself, that happens in the BatchRun class.

    Use the debugger to put a breakpoint in this class and look at the call stack to choose the better place to put your code.

    Hope this helps.

    Regards.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#2
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

#2
Guy Terry Profile Picture

Guy Terry 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans