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,
The user to impersonate.
The class to invoke in the impersonated session.
The class method to invoke in the new user context.
The parameters to pass to the method; optional.
The company that is selected for the impersonated session; optional.
The language that is selected for the impersonated session; optional.
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.
-Harry Follow us on Facebook to keep in rhythm with us. https:fb.com/theaxapta