<?xml version="1.0" encoding="utf-8"?>
<?xml-stylesheet type="text/css" href="https://www.schweda.net/style_feed.css" ?>
<rss version="2.0" 
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
    xmlns:atom="http://www.w3.org/2005/Atom"	
	xmlns:dc="http://purl.org/dc/elements/1.1/" > 
<channel>
    <title>schweda.net - Blog</title>
    <link>https://www.schweda.net/</link>
    <description>schweda.net - Blog - Blog-Beitraege</description>
    <language>de-at</language>
    <copyright>Copyright 2006-2026</copyright>
    <generator>schweda.net</generator>
    <managingEditor>heinz.schweda@schweda.net (Heinz Schweda)</managingEditor>
    <webMaster>heinz.schweda@schweda.net (Heinz Schweda)</webMaster>
    <category>Blog</category>
	<atom:link href="https://www.schweda.net/blog_rss.php?bid=508" rel="self" type="application/rss+xml" />
<item>
<title><![CDATA[Funktion als anderer Benutzer ausführen]]></title>
<description><![CDATA[
<p>&Uuml;ber die unten dargestellte Klasse m&ouml;chte ich demonstrieren, wie man in Dynamics AX 2012 eine Funktion mit den Credentials eines anderen Benutzers ausf&uuml;hrt.
</p>

<p>Die Klasse f&uuml;hrt die Funktion - im Beispiel handelt es sich um die Kreditlimitpr&uuml;fung des Debitoren <em>100001&nbsp; </em>- im ersten Schritt mit dem eigenen Benutzer und im zweiten Schritt mit den Credentials des Benutzers <em>User1 </em>aus.
</p>

<p>Aufgerufen wird die Klasse entweder &uuml;ber das Kontext-Men&uuml; im AOT bzw. &uuml;ber DEV_RunAsDemo::main(new args()).
</p>

<div class="div_blog_axcode">class DEV_RunAsDemo<br />
{<br />
}<br />
&nbsp;
</div>

<p>&nbsp;
</p>

<div class="div_blog_axcode">// Changes within this method may require (incremental) CIL compile<br />
public static server void checkCreditLimit(container _con) // incoming _con is only needed for runAs-Pattern<br />
{<br />
&nbsp;&nbsp;&nbsp; Args args = new Args();<br />
&nbsp;&nbsp;&nbsp; args.record(CustTable::find(&quot;100001&quot;));<br />
&nbsp;&nbsp;&nbsp; <br />
&nbsp;&nbsp;&nbsp; CustCreditLimit::main(args);<br />
}<br />
&nbsp;
</div>

<p>&nbsp;
</p>

<div class="div_blog_axcode">// Changes within this method requires (incremental) CIL compile<br />
private static void checkCreditLimitAsUser(container _con)&nbsp;&nbsp;&nbsp; // _con should only contain userid<br />
{<br />
&nbsp;&nbsp;&nbsp; RunAsPermission perm;<br />
&nbsp;&nbsp;&nbsp; UserId&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; runAsUser;<br />
<br />
&nbsp;&nbsp;&nbsp; runAsUser = curUserId();<br />
&nbsp;&nbsp;&nbsp; if(_con &amp;&amp; conLen(_con) == 1)<br />
&nbsp;&nbsp;&nbsp; {<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; runAsUser = conPeek(_con, 1);<br />
&nbsp;&nbsp;&nbsp; }<br />
&nbsp;&nbsp;&nbsp; perm = new RunAsPermission(runAsUser);<br />
&nbsp;&nbsp;&nbsp; perm.assert();<br />
<br />
&nbsp;&nbsp;&nbsp; runAs(runAsUser, classnum(DEV_RunAsDemo), &quot;checkCreditLimit&quot;, [runAsUser]);<br />
<br />
&nbsp;&nbsp;&nbsp; CodeAccessPermission::revertAssert();<br />
}<br />
&nbsp;
</div>

<p>&nbsp;
</p>

<div class="div_blog_axcode">public static server void main(Args args)<br />
{<br />
&nbsp;&nbsp;&nbsp; setPrefix(&quot;Credit limit check&quot;);<br />
<br />
&nbsp;&nbsp;&nbsp; DEV_RunAsDemo::checkCreditLimit(conNull()); // Container only needed for runAs-Pattern<br />
<br />
&nbsp;&nbsp;&nbsp; DEV_RunAsDemo::checkCreditLimitAsUser([&quot;User1&quot;]);<br />
}
</div>

<p>Die obenstehende Klasse ist basierend auf dem folgenden MSDN-Beitrag entstanden: <a href="http://msdn.microsoft.com/en-us/library/aa893873.aspx">http://msdn.microsoft.com/en-us/library/aa893873.aspx</a><br />
&nbsp;
</p>]]></description>
<category>Microsoft Dynamics AX (Axapta)</category>
<pubDate>Fri, 18 Apr 2014 21:03:00 +0200</pubDate>
<link>https://www.schweda.net/blog_ax.php?bid=508</link>
<comments>https://www.schweda.net/blog_ax.php?bid=508</comments>
<guid isPermaLink="true">https://www.schweda.net/blog_ax.php?bid=508</guid>
<author>heinz.schweda@schweda.net (Heinz Schweda)</author>
<wfw:commentRss>https://www.schweda.net/blog_ax.php?bid=508</wfw:commentRss>
</item>
</channel>
</rss>	
