Pages

May 01, 2019

'RunAs' method in Dynamics 365 FO

Hi Folks,

Most of us have used RunAs earlier and it has the same use in D365Fo as well. Sometimes we came across where we need to run a specific business operation under a different user account than the currently logged-in user. To achieve this we can use RunAs to execute a specific operation. This enables the caller to run an X++ method in the security context of another user. This function is most often used with batch processing or workflow submission for another user.

The syntax is really simple as below,

container runAs(
        str userId,
        int classId,
        str staticMethodName
        [,
        container params,
        str company,
        str language,
        str partition
        ])

Parameter
Description
userId
The user to impersonate.
classId
The class to invoke in the impersonated session.
staticMethodName
The class method to invoke in the new user context.
params
The parameters to pass to the method; optional. 
company
The company that is selected for the impersonated session; optional.
language
The language that is selected for the impersonated session; optional.
partition
The partition key of the type that is returned by the getCurrentPartitionfunction; optional.

Now, let's see how to implement it and take an example of submitting a PR for a different user.

I need to submit a Purchase requisition on behalf of the different user through X++ code. To get this done I need a few details all in a single container type parameter



Hope it will help.

Cheers!!!
-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta

No comments:

Post a Comment

Thanks