Thursday 21 January 2016

Using AXBuild.exe for fast compilation in Dynamics Ax 2012 R2 CU7 or above

We can compile with whole AOT in less time as compared to compilation in Mophx. From Dynamics Ax 2012 R2 cu7 and later a utility provided for this purpose.

You can found AXBuild exe from this location.
X:\Program Files\Microsoft Dynamics AX\60\Server\MicrosoftDynamicsAX\bin

And compilation command is as follow.
axbuild.exe xppcompileall /s=01 /altbin=”C:\Program Files (x86)\Microsoft Dynamics AX\60\Client\Bin” /log:”C:\Temp”
Where s=01 is the AOS server Id.

a. Must run the command prompt as administrator.
b. Account running the command must have greater rights then AOS service account.
 

Wednesday 6 January 2016

Read AD user group information from X++

static void readCompanyInfofromUserGroupWorking(Args _args)
 {
 System.DirectoryServices.DirectorySearcher directorySearcher;
 System.DirectoryServices.SearchScope searchScope;
 System.DirectoryServices.DirectoryEntry directoryEntry;
 System.DirectoryServices.SearchResultCollection searchResultCollection;
 System.DirectoryServices.SearchResult searchResult;
 System.DirectoryServices.PropertyCollection propertyCollection;
 System.DirectoryServices.PropertyValueCollection propertyValueCollection;

 str networkDomain="ax2012dev.local";

str prefix = 'LDAP://';

int totalCount;

int counter;

str groupName="AccountRecievableNew";

str groupCrit;

int usercount;

int ucount;

str userinfo;



 try


 {
 directoryEntry = new System.DirectoryServices.DirectoryEntry(prefix + networkDomain);

 searchScope = CLRInterop::parseClrEnum('System.DirectoryServices.SearchScope', 'Subtree');



 directorySearcher = new System.DirectoryServices.DirectorySearcher(DirectoryEntry);


 directorySearcher.set_SearchScope(searchScope);

 groupCrit = strfmt('(samaccountname=%1)', groupName) ;

 directorySearcher.set_Filter(strfmt('(&(objectClass=group)%1)', groupCrit));



 searchResultCollection = directorySearcher.FindAll();

 totalCount = SearchResultCollection.get_Count();

 for (counter=0; counter < totalcount; counter++)


 {
 searchResult = searchResultCollection.get_Item(counter);
 directoryEntry = searchResult.GetDirectoryEntry();
 if (directoryEntry)


 {
 propertyCollection = directoryEntry.get_Properties();
 if (propertyCollection)


 {
 propertyValueCollection = propertyCollection.get_Item('Info');

if (propertyValueCollection)


 {
 if (propertyValueCollection.get_Value())


 {
 info(propertyValueCollection.get_Value());
 }
 }
 }
 }
 }

 directorySearcher.Dispose();
 searchResultCollection.Dispose();
 }

 catch (Exception::CLRError)


 {
 error("Error reading AD");

return;


 }
 }
 

Read AD user infromation from X++

private void readCompanyInfo(NetworkAlias _alias)


 {
 InteropPermission interopPermission;
 System.DirectoryServices.DirectorySearcher directorySearcher;
 System.DirectoryServices.DirectoryEntry entry;
 System.DirectoryServices.SearchResultCollection searchResultCollection;
 System.DirectoryServices.SearchScope searchScope;
 System.DirectoryServices.SearchResult searchResult;
 System.DirectoryServices.PropertyCollection propertyCollection;
 System.DirectoryServices.PropertyValueCollection propertyValueCollection;
 str searchCriteria;

int searchCount, i, length;


 ;
 /// Search Active Directory for User details

 interopPermission = new InteropPermission(InteropKind::ClrInterop);


 interopPermission.assert();
 
 try


 {
 searchScope = System.DirectoryServices.SearchScope::Subtree;
 entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + "WIN2012SERVER"); // Change to yours

 directorySearcher = new System.DirectoryServices.DirectorySearcher(entry);

 directorySearcher.set_PageSize(65535);

 directorySearcher.set_CacheResults(false);


 directorySearcher.set_SearchScope(searchScope);
 searchCriteria = strFmt("(samaccountname=%1)", _alias);

 directorySearcher.set_Filter(strFmt('(&(objectClass=user)(objectCategory=person)%1(userAccountControl:1.2.840.113556.1.4.803:=512))', searchCriteria));


 searchResultCollection = directorySearcher.FindAll();
 searchCount = searchResultCollection.get_Count(); // In case more than 1 result is returned.

for (i = 0; i < searchCount; i++)


 {
 searchResult = searchResultCollection.get_Item(i);
 entry = searchResult.GetDirectoryEntry();
 if (entry)


 {
 propertyCollection = entry.get_Properties();
 }
 if (!propertyCollection)


 {
 entry.Dispose();
 continue;


 }
 // User properties list

try


 {
 // Company

 propertyValueCollection = propertyCollection.get_Item('Company');

if (PropertyValueCollection)


 {
 if (PropertyValueCollection.get_Value())


 {
 company = propertyValueCollection.get_Value();
 }
 }
 }
 catch (Exception::CLRError)


 {
 SRSProxy::handleClrException(Exception::Warning);
 warning(strFmt("@SYS117734"));


 }
 entry.Dispose();
 }
 searchResultCollection.Dispose();
 }
 catch (Exception::CLRError)


 {
 SRSProxy::handleClrException(Exception::Warning);
 error("@SYS117735");


 }
 CodeAccessPermission::revertAssert();
 }