Sunday 4 September 2016

Use batch processing in AX 2012 using sysframework

1. Create a service operation class ABHISalesTableService having the following class declaration:

class ABHISalesTableService 
{
}

2. Create a new method in the class giving a suitable name like processRecords having the following definition:

[SysEntryPointAttribute(false)]
public void processRecords()
{
    ABHISalesTable   abhiSalesTable;
    int             counter = 0;

    //Determines the runtime
    if (xSession::isCLRSession())
    {
        info('Running in a CLR session.');
    }
    else
    {
        info('Running in an interpreter session.');

        //Determines the tier
        if (isRunningOnServer())
        {
            info('Running on the AOS.');
        }
        else
        {
            info('Running on the Client.');
        }
    }

    //Actual operation performed
    while select forUpdate abhiSalesTable
    {
        ttsBegin;
        abhiSalesTable.Processed = NoYes::Yes;
        abhiSalesTable.update();
        ttsCommit;

        counter++;
    }

    info(strFmt("Successfully processed %1 records.", counter));
}

3. Create an action menu item ABHISalesTableService pointing to SysOperationServiceController.

4. Set the parameters of the action menu item to the service operation just created, ABHISalesTableService .processRecords.

5. Compile the service operation class and generate incremental IL.
6. Click on the action menu item to run the batch job. Check the Batch processing checkbox to run the job in CLR runtime which is the batch server execution environment.
7. Click System administration > Inquiries > Batch jobs to view the status of the job. You may also click on the Log button to view the messages written to infolog during the job execution.

Thursday 16 June 2016

AX 7 - Element, Model, Projects and Package

There are 4 main components to understand in Visual Studio include Elements, Models, Projects and Packages. To explore more let's have a look at a screenshot of the Application Explorer. Within it, there is an AOT node (Model view)



Elements:-

Elements are AOT objects, for example; Base Enums, Extended Data Types, Tables, Classes, Forms, and Menu items and a lot more.

Model :-
  1. Model is a group of elements that represents the particular solution (Tables, Forms, and Classes e.t.c) 
  2. The definition of the Model is similar to what it was in AX 2012 (AX 2012 Models) 
  3. Model is a design time concept. For example A Fleet Management Model, A Project Account Model
  4. A Model may contains multiple Visual Studio projects. However, a project many only belong to one model
  5. All of the sub-nodes below the AOT node are different models, this is call Model View
Projects:-
  1. Recommended way of development is to create Visual Studio project for all changes and the project always belongs to model, you can think of them is a subset of your model. Why do we have a different concept for model and project? The only reason we have two concepts of a model and a project is, typically AX 7 models are very large and its not a good practice to compile entire model for a simple code change activities during your development.
  2. Project always belongs to a particular model and is basically a subset of elements that belongs a model.
  3. One or more model can constitute a package, typically every package has one model. The reason sometimes we have one or more models in particular package when you customize during overlaying of source code.
Package:-
  1. A Package is a more of a compilation unit and distribution unit to move binaries and any other runtime artefacts that your model need between environments during the development ALM process. For example; moving them from the development box to the Cloud to run.
  2. A Package typically is one or more Packages typically packages into one we called deployment package and this is the unit that you use to move code to Cloud.
  3. A Package is a deployment unit that may contain one ore more models. In addition to elements, it includes more metadata, which is a description data that defines the properties and behaviour of the model.
  4. A Package can be exported into a file which can then be deployed into a staging or production environment.
Keep tuned for more on AX 7.

Monday 30 May 2016

Add All Objects To TFS


static void versionControl(Args _args)
{
    UtilElements   utilElements;
    TreeNode       treeNode;
 
    //Desired Layer
    UtilEntryLevel utilEntryLevel = UtilEntryLevel::var;
 
    //This container is important, so you don't add a single classMethod to versionControl,
    //If you do that, you are going to have some trouble to check-in them.
    container      conElementType = [UtilElementType::Class,UtilElementType::ConfigurationKey,
                                    UtilElementType::Enum,UtilElementType::ExtendedType,
                                    UtilElementType::Form,UtilElementType::Macro,
                                    UtilElementType::Menu,UtilElementType::Report,
                                    UtilElementType::SecurityKey, UtilElementType::SharedProject,
                                    UtilElementType::Table, UtilElementType::ActionTool,
                                    UtilElementType::DisplayTool, UtilElementType::OutputTool];
 
    //Checking if the recordType is inside the valid container
    boolean isValidForVersionControl(UtilElementType _type)
    {
        return confind(conElementType,_type);
    }
    ;
 
    //If the Version Control is not enable, it does not
    // make sense to add elements to it
    if(SysVersionControlParameters::isVCSEnabled())
    {
        //Iterate over the elements of an specific layer
        while select utilElements
            where utilElements.utilLevel == utilEntryLevel
        {
            //Validate if the UtilElment is to be addded to the versionControl
            //based on the recordType field
            if(isValidForVersionControl(utilElements.recordType))
            {
                //Get the AOT tree node
                treeNode = xUtilElements::getNode(utilElements);
 
                //Used to check if it is already added and other stuff
                if(versionControl.allowCreate(treenode))
                {
                    //Call to the VersionControl Appl class, already instantiated by the client
                    versioncontrol.create(treeNode);
                }
            }
         }
     }
     else warning("Version Control not enabled");
}
 
Comment
 
\Classes\SysTreeNode\canCreate
 
 
/*if (!SysTreeNode::existsInLayer(this.parmTreeNode(), currentLayer))   // check if sub-elements' layer is in layer mask
    {
        error(strFmt("@SYS127511", this.parmTreeNode().treeNodePath(), currentLayer));
        return false;
    }*/
 
 
 

Friday 27 May 2016

AX SSRS Report times out after 10 minutes (Error: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond)

Sometimes when running a report that is going to return a large data set you may get the following error message after 10 minutes:

"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond"

Whenever you receive this error the first thing you should look at is your DP class and can performance be improved by rewriting some of your code. If it cant be or this is a default ax report sometimes your only option is to increase the default timeout period.

In order to increase the timeout for an AX SSRS report you need to do the following:

1.) Create a new client config(or copy an existing one.) This is the same config that could be used as your .axc file that is used to access different environments/aos. However this will have larger timeout values in it so only use this on the server mentioned in step 4. You do not need your user's applications config to have these settings.

2.) Update the binding node of "QueryServiceBinding" and change the sendTimeout property from "00:10:00" (10 minutes) to whatever timeout value you like in hh:mm:ss format. You can also update any other timeout setting as well if you like. (Just search for 00:10:00 within the document and replace it with your new time)

3.) Save the new config as  "Microsoft.Dynamics.AX.ReportConfiguration.axc"

4.) Copy the new file Microsoft.Dynamics.AX.ReportConfiguration.axc into the following folder on your sql/ssrs server (inside of the os/windows file system)

C:\Program Files\Microsoft SQL Server\MSRS11.<AOS>\Reporting Services\ReportServer\bin

Note: This is for a sql2012 instance. If you are running a different version of ms sql please refer to the following TechNet article to find the location of your report server bin folder https://technet.microsoft.com/en-us/library/hh389774.aspx if you need help locating it.

5.) Run the report and the report should no longer time out. You do not need to restart the aos, sql or ssrs services in order for the changes to take place once the file is in this folder it should now respect your new timeout settings

Sunday 24 April 2016

Writing Data to Excel file


How it works
1. Use SysExcelApplication class to create excel file.
2. Use SysExcelWorkbooks and SysExcelWorkbook to create a blank workbook(by default 3 worksheets will be available).
3. Use SysExcelWorkSheets to select worksheet for writing data.
4. SysExcelCells to select the cells in the excel for writing the data.
5. SysExcelCell to write the data in the selected cells.
6. Once you done with write operation use SysExcelApplication.visible to open
file.

static void Write2ExcelFile(Args _args)
{
InventTable inventTable;
SysExcelApplication application;
SysExcelWorkbooks workbooks;
SysExcelWorkbook workbook;
SysExcelWorksheets worksheets;
SysExcelWorksheet worksheet;
SysExcelCells cells;
SysExcelCell cell;
int row;
;
application = SysExcelApplication::construct();
workbooks = application.workbooks();
workbook = workbooks.add();
worksheets = workbook.worksheets();
worksheet = worksheets.itemFromNum(1);
cells = worksheet.cells();
cells.range('A:A').numberFormat('@');
cell = cells.item(1,1);
cell.value("Item");
cell = cells.item(1,2);
cell.value("Name");
row = 1;
while select inventTable
{
row++;
cell = cells.item(row, 1);
cell.value(inventTable.ItemId);
cell = cells.item(row, 2);
cell.value(inventTable.ItemName);
}
application.visible(true);
}

Sunday 6 March 2016

Disable UAC on windows server 2012 r2

UAC has to be turned off via registry by changing the DWORD "EnableLUA" from 1 to 0 in "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\policies\system". You will get a notification that a reboot is required. After the reboot, UAC is disabled.
After UAC is disabled, the issue is resolved.

Friday 26 February 2016

AxBuild command in AX 2012

1. To start a AxBuild compile, you need to have CU7 update for Ax 2012 R2, make sure that you have axbuild.exe files in C:\Program Files\Microsoft Dynamics AX\60\Server\bin
2. Stope the AOS
3. Open command prompt as an administrator
4. Go to AxBuild path C:\Program Files\Microsoft Dynamics AX\60\Server\bin
5. Run below command.

 AxBuild.exe xppcompileall /s=01 /altbin="C:\Program Files (x86)\Microsoft Dynamics AX\6.0\Client\Bin"

Monday 15 February 2016

The model store has been modified

AXUTIL set /noinstallmode

Update cross reference in batch in Dynamics AX 2012

The information in this post is based on Dynamics AX 2012 R3. It may or may not be valid for other versions.


static void UpdateCrossRefBatch(Args _args)
{
    ;

    xRefUpdate::truncateXrefTables();
    xRefUpdateIL::updateAllXref(true, false, true);
    info("Done, cross reference update batch job created.");
}

Sunday 14 February 2016

SQL query to know AX database restore history

SELECT [rs].[destination_database_name] ,

[rs].[restore_date] ,

[bs].[backup_start_date] ,

[bs].[backup_finish_date] ,

[bs].[database_name] AS [source_database_name] ,

[bmf].[physical_device_name] AS [backup_file_used_for_restore]

FROM msdb..restorehistory rs

INNER JOIN msdb..backupset bs ON [rs].[backup_set_id] = [bs].[backup_set_id]

INNER JOIN msdb..backupmediafamily bmf ON [bs].[media_set_id] = [bmf].[media_set_id]

ORDER BY [rs].[restore_date] DESC

Friday 12 February 2016

Users attached with role

Exportfile for AOT version 1.0 or later
Formatversion: 1
***Element: FRM
; Microsoft Dynamics AX Forms unloaded
; --------------------------------------------------------------------------------
FRMVERSION 12
FORM #SysUserInfoPage
  PROPERTIES
    Name                #SysUserInfoPage
    Origin              #{ED80CF56-7E83-4BA9-BC98-F4C39DC7FEFA}
  ENDPROPERTIES
 
  METHODS
    SOURCE #classDeclaration
      #class FormRun extends ObjectRun
      #{
      #    #Admin
      #    #Guest
      #    #resAppl
      #
      #    #define.AOSUser('-AOS-')
      #    #define.ENUM_FORMSTYLE_AUTO(0)
      #    #define.WINDOWTYPE_STANDARDWINDOW(0)
      #
      #    str aliasText;
      #    str aliasUserId;
      #    boolean inAliasTextChange;
      #
      #    str domainText;
      #    str domainUserId;
      #    boolean inDomainTextChange;
      #
      #    str nameText;
      #    boolean inNameTextChange;
      #
      #    boolean enabledOnce;
      #
      #    //Profile tab related
      #    boolean     profileTabLoaded;
      #    Map         origPerCompanyProfiles;
      #    List        companyIds;
      #    ProfileId   origAllCompaniesProfile;
      #
      #    #define.ProfileTypeNone(0)
      #    #define.ProfileTypeAll(1)
      #    #define.ProfileTypeSpecific(2)
      #
      #    #define.CompanySpecificProfilesColCompany(1)
      #    #define.CompanySpecificProfilesColProfile(2)
      #
      #    List regForUserSelChange;
      #
      #    Object caller;
      #    boolean isEditMode;
      #}
    ENDSOURCE
    SOURCE #close
      #public void close()
      #{
      #    // Clear out the list to prevent circular form references
      #    regForUserSelChange = new List(Types::Class);
      #
      #    super();
      #    SysSecurity::reload(false);
      #}
    ENDSOURCE
    SOURCE #generateInitialUserId
      #// Generates the 5 character user id from an alias
      #str generateInitialUserId(str _alias)
      #{
      #    UserInfo ui;
      #    boolean found = false;
      #    Name alias2;
      #
      #    if(strLen(_alias) <= 5 && strLen(_alias) > 0)
      #    {
      #        alias2 = _alias;
      #
      #        // If the alias is already used, return empty
      #        while select firstonly RecId from ui where ui.Id == alias2
      #        {
      #            found = true;
      #            break;
      #        }
      #
      #        if(!found)
      #        {
      #            return _alias;
      #        }
      #    }
      #
      #    return '';
      #}
      #
    ENDSOURCE
    SOURCE #generateInitialUserSid
      #// Generates a user SID from the user id and domain name
      #str generateInitialUserSid(str userId, str domainName, UserAccountType accountType)
      #{
      #    xAxaptaUserManager axUsrMgr;
      #    xAxaptaUserDetails axUsrDet;
      #    str userSid;
      #    int len;
      #
      #    if(domainName == '' || userId == '')
      #    {
      #        return '';
      #    }
      #
      #    // Instantiate AxaptaUserManager and get user's details
      #    axUsrMgr = new xAxaptaUserManager();
      #    //axUsrDet = axUsrMgr.getDomainUser(domainName, userId);
      #    try
      #    {
      #        len = infologLine();
      #        axUsrDet = axUsrMgr.getSIDFromName(userId, domainName, accountType);
      #    }
      #    catch(Exception::Error)
      #    {
      #        infolog.clear(len);
      #        throw error(accountType == UserAccountType::ClaimsUser ? "@SYS330368" : "@SYS90055");
      #    }
      #    try
      #    {
      #        if(axUsrDet && axUsrDet.getUserCount() > 0 && axUsrDet.isUserEnabled(0))
      #        {
      #            userSid = axUsrDet.getUserSid(0);
      #        }
      #
      #        return userSid;
      #    }
      #    catch(Exception::Error)
      #    {
      #        len = infologLine();
      #        if(len > 0)
      #        {
      #            infolog.clear(len - 1);
      #        }
      #        return '';
      #    }
      #}
      #
    ENDSOURCE
    SOURCE #getUserId
      #public FieldValue getUserId()
      #{
      #    return userInfo.Id;
      #}
    ENDSOURCE
    SOURCE #init
      #void init()
      #{
      #    isEditMode = false;
      #    regForUserSelChange = new List(Types::Class);
      #    if (!regForUserSelChange) info('regForUserSelChange ' + "@SYS309925");
      #
      #    caller = element.args().caller();
      #    if (caller != null && caller is FormRun && caller.name() == formStr(SysUserInfoPage))
      #    {
      #        element.launchAsStandardPage();
      #        isEditMode = true;
      #    }
      #
      #    super();
      #
      #    inAliasTextChange = false;
      #    inDomainTextChange = false;
      #    inNameTextChange = false;
      #    enabledOnce = false;
      #
      #    companyIds = new List(Types::String);
      #
      #    if (isEditMode)
      #    {
      #        grid.allowEdit(true);
      #        mnuItmBtnEditInGrid.visible(false);
      #    }
      #}
    ENDSOURCE
    SOURCE #launchAsStandardPage
      #private void launchAsStandardPage()
      #{
      #    element.form().design().style(#ENUM_FORMSTYLE_AUTO);
      #    element.form().design().windowType(#WINDOWTYPE_STANDARDWINDOW);
      #}
    ENDSOURCE
    SOURCE #launchDetailsPage
      #public void launchDetailsPage(OpenMode _mode)
      #{
      #    Args args;
      #    MenuFunction menuFunction;
      #
      #    args = new Args();
      #    args.caller(element);
      #    menuFunction = new MenuFunction(menuitemDisplayStr(SysUserInfoDetail), MenuItemType::Display);
      #    menuFunction.openMode(_mode);
      #    menuFunction.run(args);
      #}
    ENDSOURCE
    SOURCE #refresh
      #public void refresh()
      #{
      #    element.lockWindowUpdate(true);
      #    refreshButton.clicked();
      #    element.lockWindowUpdate(false);
      #}
    ENDSOURCE
    SOURCE #refreshUserInfo
      #void refreshUserInfo()
      #{
      #    userInfo_DS.reread();
      #}
      #
    ENDSOURCE
    SOURCE #registerForUserSelChange
      #public boolean registerForUserSelChange(Object _part)
      #{
      #    regForUserSelChange.addEnd(_part);
      #    _part.updateSelection(userInfo.Id);
      #    //info('registering Part ' + _part.toString() + ', ' + regForUserSelChange.toString());
      #    return true;
      #}
    ENDSOURCE
    SOURCE #updateCaller
      #void updateCaller()
      #{
      #    if (caller)
      #    {
      #        caller.updateGrid();
      #    }
      #}
    ENDSOURCE
    SOURCE #updateGrid
      #public void updateGrid()
      #{
      #    userInfo_ds.research(true);
      #}
    ENDSOURCE
    SOURCE #validateAdmin
      #boolean validateAdmin()
      #{
      #    return UserInfoHelp::validateAdmin(userInfo);
      #}
    ENDSOURCE
    SOURCE #validateOnline
      #//AosRunMode::Client
      #boolean validateOnline()
      #{
      #    if (SysUsersOnline::isUserOnline(userInfo.Id))
      #    {
      #        throw error("@SYS26837");
      #    }
      #    return true;
      #}
    ENDSOURCE
  ENDMETHODS
  OBJECTBANK
    PROPERTIES
    ENDPROPERTIES
   
    DATASOURCE
      OBJECTPOOL
        PROPERTIES
          Name                #UserInfo
          Table               #UserInfo
          InsertAtEnd         #No
          InsertIfEmpty       #No
        ENDPROPERTIES
       
        FIELDLIST
          DATAFIELD id
            PROPERTIES
            ENDPROPERTIES
           
            METHODS
              SOURCE #validate
                #public boolean validate()
                #{
                #    return true;
                #}
                #
              ENDSOURCE
            ENDMETHODS
          ENDDATAFIELD
         
          DATAFIELD enable
            PROPERTIES
            ENDPROPERTIES
           
            METHODS
              SOURCE #validate
                #boolean validate()
                #{
                ##define.Tab('\t')
                ##define.Space(' ')
                #
                #    boolean ret;
                #    Sid usersid;
                #    TextBuffer txtBuf;
                #    UserInfo ui2;
                #    Name userId;
                #    ;
                #
                #    if (!userInfo.Enable)
                #    {
                #        ret = element.validateAdmin() && super();
                #        userInfo.ExternalUser = false;
                #        //userInfo.Sid = '';
                #        grid.update();
                #    }
                #    else
                #    {
                #        try
                #        {
                #            userId = userInfo.Id;
                #
                #            if(userId == #GuestUser)
                #            {
                #                return true;
                #            }
                #
                #            if(userId == '')
                #            {
                #                error("@SYS91134");
                #                return false;
                #            }
                #
                #            if(userId == #AOSUser)
                #            {
                #                error("@SYS98151");
                #                return false;
                #            }
                #
                #            select firstonly ui2 where ui2.RecId != userInfo.RecId && ui2.Id == userId;
                #            if(ui2)
                #            {
                #                error(strFmt("@SYS93693", userId));
                #                userInfo.Id = '';
                #                return false;
                #            }
                #
                #            txtBuf = new TextBuffer();
                #            txtBuf.appendText(userId);
                #
                #            // User id can not contain any white space
                #            if(txtBuf.find(#Space) || txtBuf.find(#Tab))
                #            {
                #                error("@SYS91132");
                #                return false;
                #            }
                #
                #            // Generate a user SID from the user id and domain name, display error if SID not generated
                #            usersid = element.generateInitialUserSid(userInfo.NetworkAlias, userInfo.NetworkDomain, userInfo.AccountType);
                #            if(usersid == '')
                #            {
                #                Box::stop(userInfo.AccountType == UserAccountType::ClaimsUser ? "@SYS330368" : "@SYS90055");
                #
                #                return false;
                #            }
                #
                #            // Search for the same SID in the table
                #            select firstonly ui2 where ui2.Sid == usersid && userInfo.Enable && ui2.Id != userId;
                #            if(ui2)
                #            {
                #                // If the SID is already present in the table, display an error
                #                error("@SYS93694");
                #                return false;
                #            }
                #
                #            userInfo.Sid = usersid;
                #
                #            select * from ui2;
                #
                #            aliasText = userInfo_NetworkAlias.text();
                #            domainText = userInfo_NetworkDomain.text();
                #            nameText = userInfo_Name.text();
                #            userInfo.EnabledOnce = true;
                #        }
                #        catch(Exception::Error)
                #        {
                #            return false;
                #        }
                #
                #        ret = super();
                #    }
                #
                #    return ret;
                #}
              ENDSOURCE
            ENDMETHODS
          ENDDATAFIELD
         
          DATAFIELD networkDomain
            PROPERTIES
            ENDPROPERTIES
           
            METHODS
              SOURCE #validate
                #public boolean validate()
                #{
                #    boolean ret;
                #    ;
                #
                #    userinfo.NetworkDomain = strLRTrim(userinfo.NetworkDomain);
                #
                #    ret = super();
                #
                #    return ret;
                #}
                #
              ENDSOURCE
            ENDMETHODS
          ENDDATAFIELD
         
          DATAFIELD networkAlias
            PROPERTIES
            ENDPROPERTIES
           
            METHODS
              SOURCE #validate
                #public boolean validate()
                #{
                #    boolean ret;
                #    ;
                #
                #    userinfo.NetworkAlias = strLRTrim(userinfo.NetworkAlias);
                #
                #    ret = super();
                #
                #    return ret;
                #}
              ENDSOURCE
            ENDMETHODS
          ENDDATAFIELD
         
        ENDFIELDLIST
      ENDOBJECTPOOL
      METHODS
        SOURCE #selectionChanged
          #public void selectionChanged()
          #{
          #    Object partRegistered;
          #    ListEnumerator partEnum;
          #
          #    super();
          #
          #    if (regForUserSelChange)
          #    {
          #        partEnum = regForUserSelChange.getEnumerator();
          #        while (partEnum.moveNext())
          #        {
          #            partRegistered = partEnum.current();
          #            // info(selectedRole.Name);
          #            // info('sc: callback for ' + partRegistered.toString());
          #            partRegistered.updateSelection(userInfo.Id);
          #        }
          #    }
          #}
        ENDSOURCE
        SOURCE #reread
          #//Fired when the record is restored
          #public void reread()
          #{
          #    super();
          #
          #    if (profileTabLoaded && this.forceWrite())
          #    {
          #        this.forceWrite(false);
          #    }
          #}
        ENDSOURCE
        SOURCE #validateWrite
          #public boolean validateWrite()
          #{
          #    str alias;
          #    userId userId;
          #    str domainName;
          #    xAxaptaUserManager mgr;
          #    xAxaptaUserDetails det;
          #    xAxaptaUserDetails det2;
          #    boolean userInDb = false;
          #    UserInfo ui2;
          #    sid userSid;
          #    int len;
          #    UserInfo adminRecord;
          #    ;
          #
          #    userId = userInfo.Id;
          #
          #    if(userId == #AOSUser)
          #    {
          #        error("@SYS98151");
          #        return false;
          #    }
          #
          #    select adminRecord where adminRecord.Id == #AdminUser;
          #    if(adminRecord.RecId)
          #    {
          #        if(userinfo.Language == '')
          #        {
          #            userinfo.Language = adminRecord.Language;
          #        }
          #
          #        if(userinfo.Helplanguage == '')
          #        {
          #            userinfo.Helplanguage = adminRecord.Helplanguage;
          #        }
          #    }
          #    else
          #    {
          #       select adminRecord where adminRecord.Id == curUserId();
          #        if (adminRecord)
          #        {
          #            if(userinfo.Language == '')
          #            {
          #                userinfo.Language = adminRecord.Language;
          #            }
          #
          #            if(userinfo.Helplanguage == '')
          #            {
          #                userinfo.Helplanguage = adminRecord.Helplanguage;
          #            }
          #        }
          #    }
          #
          #    if(!super() || userId == '')
          #    {
          #        return false;
          #    }
          #
          #    mgr = new xAxaptaUserManager();
          #    alias = userInfo.NetworkAlias;
          #    domainName = userInfo.NetworkDomain;
          #
          #    // Get the single user's details from the kernel class
          #    //det = mgr.getDomainUser(domainName, alias);
          #    try
          #    {
          #        len = infologLine();
          #        det = mgr.getSIDFromName(alias, domainName, userInfo.AccountType);
          #    }
          #    catch(Exception::Error)
          #    {
          #        infolog.clear(len);
          #        throw error(userInfo.AccountType == UserAccountType::ClaimsUser ? "@SYS330368" : "@SYS90055");
          #    }
          #
          #    // If Admin alias/domain are getting changed, update SID
          #    if(userInfo.Id == #AdminUser)
          #    {
          #        try
          #        {
          #            if(det && det.getUserCount() > 0 && det.isUserEnabled(0))
          #            {
          #                userSid = det.getUserSid(0);
          #            }
          #
          #            if(userSid == '')
          #            {
          #                return false;
          #            }
          #
          #            select ui2 where ui2.Sid == userSid && ui2.Id != #AdminUser;
          #            if(ui2)
          #            {
          #                error("@SYS93694");
          #                return false;
          #            }
          #        }
          #        catch(Exception::Error)
          #        {
          #            len = infologLine();
          #            if(len > 0)
          #            {
          #                infolog.clear(len - 1);
          #            }
          #            Box::stop(userInfo.AccountType == UserAccountType::ClaimsUser ? "@SYS330368" : "@SYS90055");
          #            return false;
          #        }
          #    }
          #
          #    // Verify duplicate user id
          #    select firstonly ui2 where ui2.Id == userId;
          #    if(ui2)
          #    {
          #        if(ui2.RecId == userInfo.RecId)
          #        {
          #            userInDb = true;
          #        }
          #        else
          #        {
          #            error(strFmt("@SYS93693", userId));
          #            userInfo.Id = '';
          #            return false;
          #        }
          #    }
          #
          #    // Validate for all the users for which Enabled checkbox is checked
          #    if(userInfo.Enable)
          #    {
          #        if(userId != #GuestUser && (alias == '' || domainName == ''))
          #        {
          #            error("@SYS93695");
          #            return false;
          #        }
          #
          #        if(det != null && det.getUserCount() > 0 && det.isUserEnabled(0))
          #        {
          #            userInfo.ExternalUser = det.isUserExternal(0);
          #            userInfo.Sid = det.getUserSid(0);
          #            userInfo.NetworkDomain = det.getUserDomain(0);
          #            userInfo.AccountType = det.getAccountType(0);
          #
          #            if(userInfo.Enable)
          #            {
          #                userInfo.EnabledOnce = true;
          #                if(!userInfo.orig() || !userInfo.orig().EnabledOnce)
          #                {
          #                    // must reread the details structure using the getDomainUser API
          #                    // because the user name returned by getSidFromName is incorrect
          #                    // Note, however, that getDomainUser will not return details for a claims user
          #                    det2 = mgr.getDomainUser(domainName,  alias);
          #                    if(userInfo.Name == '')
          #                    {
          #                        userInfo.Name = (det2) ? det2.getUserName(0) : det.getUserName(0);
          #                    }
          #                    userEmail.text((det2) ? det2.getUserMail(0) : det.getUserMail(0));
          #                }
          #            }
          #        }
          #        else if(userId != #GuestUser)
          #        {
          #            error(userInfo.AccountType == UserAccountType::ClaimsUser ? "@SYS330368" : "@SYS90055");
          #            return false;
          #        }
          #    }
          #    else
          #    {
          #        // Uncheck the External checkbox since user is not enabled
          #        userInfo.ExternalUser = false;
          #
          #        if(!userInDb)
          #        {
          #            warning("@SYS93696");
          #        }
          #    }
          #
          #    return true;
          #}
          #
        ENDSOURCE
        SOURCE #write
          #void write()
          #{
          #    SysUserInfo sysUserInfo2;
          #
          #    userInfo.Id = strLTrim(strRTrim(userInfo.Id));
          #    userInfo.NetworkAlias = strLTrim(strRTrim(userInfo.NetworkAlias));
          #    userInfo.Name = strLTrim(strRTrim(userInfo.Name));
          #
          #    super();
          #
          #    ttsbegin;
          #    select firstonly RecId from sysUserInfo2
          #        where sysUserInfo2.Id == userinfo.Id;
          #
          #    if (!sysUserInfo2)
          #    {
          #        sysUserInfo2.initValue();
          #        sysUserInfo2.Email = userEmail.text();
          #        sysUserInfo2.Id = userinfo.Id;
          #        sysUserInfo2.insert();
          #    }
          #    else
          #    {
          #        sysUserInfo2.Email = userEmail.text();
          #    }
          #
          #    ttscommit;
          #
          #    SecurityKeySet::reloadDomainRestrictions();
          #    element.updateCaller();
          #}
          #
        ENDSOURCE
        SOURCE #create
          #public void create(boolean _append = false)
          #{
          #    element.launchDetailsPage(OpenMode::New);
          #}
        ENDSOURCE
        SOURCE #initValue
          #void initValue()
          #{
          #    Sid newSid = '';
          #
          #    infolog.getUserSetup().setDefaults(userInfo);
          #    userInfo.Enable = false;
          #
          #    newSid = userInfo.Sid;
          #
          #    super();
          #
          #    if(newSid == '' && newSid != userInfo.Sid)
          #    {
          #        userInfo.Sid = '';
          #    }
          #
          #    userInfo.Enable = false;
          #    userInfo.NetworkAlias = '';
          #    userInfo.NotifyTimeZoneMismatch = true;
          #}
        ENDSOURCE
        SOURCE #delete
          #void delete()
          #{
          #    SysUserLog              sysUserLog;
          #    SysUserInfo             sysUserInfo;
          #    DirPersonUser           dirPersonUser;
          #
          #    startLengthyOperation();
          #
          #    if(userInfo.Id == #GuestUser)
          #    {
          #        error(strFmt("@SYS29012", userInfo.Id));
          #        endLengthyOperation();
          #        return;
          #    }
          #
          #    if(element.validateAdmin() && element.validateOnline())
          #    {
          #        ttsbegin;
          #
          #        delete_from sysUserLog
          #            where sysUserLog.UserId == userInfo.Id;
          #
          #        delete_from sysUserInfo
          #            where sysUserInfo.Id == userInfo.Id;
          #
          #        delete_from dirPersonUser
          #            where dirPersonUser.User == userInfo.Id;
          #
          #        infolog.profileMgr().removeUserFromAllProfiles(userInfo.Id);
          #
          #        super();
          #        ttscommit;
          #    }
          #    element.updateCaller();
          #    endLengthyOperation();
          #}
        ENDSOURCE
        SOURCE #active
          #int active()
          #{
          #    int ret;
          #
          #    ret = super();
          #
          #    // Not allowed to create user relations for AD group account types.
          #    mnuItBtnRelations.enabled(userInfo.AccountType != UserAccountType::ADGroup);
          #
          #    profileTabLoaded = false;
          #    return ret;
          #}
        ENDSOURCE
      ENDMETHODS
    ENDDATASOURCE
  ENDOBJECTBANK
 
  REFERENCEDATASOURCES
  ENDREFERENCEDATASOURCES
 
  JOINS
  ENDJOINS
 
  PARTREFERENCES
    PARTREFERENCE #partRolesForUser
      PROPERTIES
        Name                #partRolesForUser
        MenuItemName        #SysSecPartRolesForUser
        DataSource          #UserInfo
        ElementPosition     #536870911
      ENDPROPERTIES
     
    ENDPARTREFERENCE
   
    PARTREFERENCE #SysSecPartUserLog
      PROPERTIES
        Name                #SysSecPartUserLog
        MenuItemName        #SyssecpartuserLog
        DataSource          #UserInfo
        DataSourceRelation  #SysUserLog.UserInfo
        IsLinked            #Yes
        ElementPosition     #1073741822
      ENDPROPERTIES
     
    ENDPARTREFERENCE
   
    PARTREFERENCE #partProfiles
      PROPERTIES
        Name                #partProfiles
        MenuItemName        #SysSecPartProfilesForUser
        DataSource          #UserInfo
        IsLinked            #Yes
        ElementPosition     #1610612733
      ENDPROPERTIES
     
    ENDPARTREFERENCE
   
  ENDPARTREFERENCES
 
  DESIGN
    PROPERTIES
      Caption             #@SYS25412
      UseCaptionFromMenuItem  #Yes
      TitleDatasource     #UserInfo
      WindowType          #ContentPage
      SetCompany          #No
      DataSource          #UserInfo
      Style               #ListPage
    ENDPROPERTIES
   
    CONTAINER
      CONTROL ACTIONPANE
        PROPERTIES
          Name                #ActionPane
          ElementPosition     #715827882
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL ACTIONPANETAB
        PROPERTIES
          Name                #ActionPaneTab
          Width               #Column width
          ElementPosition     #1073741823
          HierarchyParent     #ActionPane
          Caption             #@SYS25412
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL BUTTONGROUP
        PROPERTIES
          Name                #AttachmentsGroup
          ElementPosition     #2080374782
          HierarchyParent     #ActionPaneTab
          Caption             #@SYS316708
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL BUTTONGROUP
        PROPERTIES
          Name                #btnGrpMaintain
          ElementPosition     #1610612734
          HierarchyParent     #ActionPaneTab
          Caption             #@SYS116749
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL BUTTONGROUP
        PROPERTIES
          Name                #btnGrpNew
          ElementPosition     #1342177278
          HierarchyParent     #ActionPaneTab
          Caption             #@SYS300817
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL BUTTONGROUP
        PROPERTIES
          Name                #btnGrpView
          ElementPosition     #1744830462
          HierarchyParent     #ActionPaneTab
          Caption             #@SYS342635
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL BUTTONGROUP
        PROPERTIES
          Name                #List
          ElementPosition     #1979711486
          HierarchyParent     #ActionPaneTab
          Caption             #@SYS6188
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL BUTTONGROUP
        PROPERTIES
          Name                #relatedInformation
          ElementPosition     #1879048190
          HierarchyParent     #ActionPaneTab
          Caption             #@SYS323065
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL GRID
        PROPERTIES
          Name                #Grid
          AutoDeclaration     #Yes
          AllowEdit           #No
          Width               #Column width
          Height              #Column height
          ElementPosition     #1431655764
          DataSource          #UserInfo
          DefaultAction       #LaunchDefaultAction
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL CHECKBOX
        PROPERTIES
          Name                #UserInfo_Enabled
          Width               #50
          ElementPosition     #2130706430
          HierarchyParent     #Grid
          BackgroundColor     #Window background
          Label               #@SYS60755
          LabelWidth          #25
          DataSource          #UserInfo
          DataField           #enable
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL CHECKBOX
        PROPERTIES
          Name                #UserInfo_External
          AllowEdit           #No
          Width               #50
          ElementPosition     #2139095038
          HierarchyParent     #Grid
          BackgroundColor     #Window background
          Label               #@SYS69716
          LabelWidth          #25
          DataSource          #UserInfo
          DataField           #externalUser
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL COMBOBOX
        PROPERTIES
          Name                #UserInfo_accountType
          AutoDeclaration     #Yes
          HelpText            #@SYS329691
          ElementPosition     #984263336
          HierarchyParent     #Grid
          Label               #@SYS27730
          DataSource          #UserInfo
          DataField           #accountType
        ENDPROPERTIES
       
        METHODS
          SOURCE #selectionChange
            #public int selectionChange()
            #{
            #    int ret = false;
            #
            #    if ((userInfo.Id != #GuestUser) && (!userInfo.EnabledOnce || userInfo.Id == #AdminUser))
            #    {
            #        ret = super();
            #    }
            #    else
            #    {
            #        this.text(enum2str(userInfo.AccountType));
            #        this.update();
            #    }
            #
            #    return ret;
            #}
          ENDSOURCE
        ENDMETHODS
      ENDCONTROL
     
      CONTROL COMMANDBUTTON
        PROPERTIES
          Name                #cmdBtnNew
          AutoDeclaration     #Yes
          ElementPosition     #1073741822
          HierarchyParent     #btnGrpNew
          Text                #@SYS16181
          ButtonDisplay       #Text & Image above
          NormalImage         #10565
          ImageLocation       #EmbeddedResource
          Big                 #Yes
          Primary             #Yes
          Command             #260
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL COMMANDBUTTON
        PROPERTIES
          Name                #mnuItBtnRemove
          ElementPosition     #1908874351
          HierarchyParent     #btnGrpMaintain
          Text                #@SYS300820
          ButtonDisplay       #Text & Image above
          NormalImage         #10121
          ImageLocation       #EmbeddedResource
          MultiSelect         #Yes
          Primary             #Yes
          Command             #2832
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL COMMANDBUTTON
        PROPERTIES
          Name                #refreshButton
          AutoDeclaration     #Yes
          HelpText            #@SYS315818
          ElementPosition     #1073741822
          HierarchyParent     #List
          Text                #@SYS29018
          NormalImage         #11437
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          Command             #2875
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL COMMANDBUTTON
        PROPERTIES
          Name                #SendToExcel
          HelpText            #@SYS315819
          ElementPosition     #1610612733
          HierarchyParent     #List
          Text                #@SYS134461
          NormalImage         #10156
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          MultiSelect         #Yes
          Big                 #Yes
          Command             #4436
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #ABH_UserattachedwithRole
          ElementPosition     #1879048189
          HierarchyParent     #List
          Text                #Users attached with role
          NormalImage         #10156
          ImageLocation       #EmbeddedResource
          MultiSelect         #No
          Big                 #Yes
          MenuItemType        #Action
          MenuItemName        #ABH_UserattachedwithRole
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #LaunchDefaultAction
          AutoDeclaration     #Yes
          Visible             #No
          ElementPosition     #2087831322
          HierarchyParent     #btnGrpMaintain
          ButtonDisplay       #Text & Image above
          NormalImage         #10040
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          DataSource          #UserInfo
          MenuItemName        #SysUserInfoDetail
        ENDPROPERTIES
       
        METHODS
          SOURCE #clicked
            #void clicked()
            #{
            #    element.launchDetailsPage(isEditMode ? OpenMode::Edit : OpenMode::View);
            #}
          ENDSOURCE
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mibDocuView
          AllowEdit           #No
          HelpText            #@SYS128646
          ElementPosition     #1431655764
          HierarchyParent     #AttachmentsGroup
          Text                #@SYS316600
          NormalImage         #10442
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          MenuItemName        #DocuView
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mnuItBtnDetails
          AutoDeclaration     #Yes
          HelpText            #@SYS107224
          ElementPosition     #1789569704
          HierarchyParent     #btnGrpMaintain
          Text                #@SYS308814
          ButtonDisplay       #Text & Image above
          NormalImage         #10040
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          Primary             #Yes
          DataSource          #UserInfo
          MenuItemName        #SysUserInfoDetail
        ENDPROPERTIES
       
        METHODS
          SOURCE #clicked
            #void clicked()
            #{
            #    element.launchDetailsPage(OpenMode::Edit);
            #}
          ENDSOURCE
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mnuItBtnImport
          HelpText            #@SYS322381
          ElementPosition     #1610612733
          HierarchyParent     #btnGrpNew
          Text                #@SYS105127
          ButtonDisplay       #Text & Image above
          NormalImage         #11328
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          MenuItemName        #SysSecUserAddRoles
        ENDPROPERTIES
       
        METHODS
          SOURCE #clicked
            #void clicked()
            #{
            #    SysUserADUserImportWizard wizard;
            #    ;
            #
            #    wizard = SysUserADUserImportWizard::construct();
            #
            #    wizard.setDomainsEnumerated(false);
            #    if (wizard.prompt())
            #        wizard.run();
            #
            #    userInfo_ds.executeQuery();
            #    grid.update();
            #    element.updateCaller();
            #}
            #
          ENDSOURCE
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mnuItBtnLog
          ElementPosition     #1073741822
          HierarchyParent     #relatedInformation
          Text                #@SYS179648
          ButtonDisplay       #Text & Image above
          NormalImage         #10835
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          Primary             #Yes
          MenuItemName        #SysUserLog
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mnuItBtnOnlineTime
          ElementPosition     #1610612733
          HierarchyParent     #relatedInformation
          Text                #@SYS69324
          ButtonDisplay       #Text & Image above
          NormalImage         #11013
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          Primary             #Yes
          MenuItemType        #Output
          MenuItemName        #SysUsersOnlineReport
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mnuItBtnOptions
          ElementPosition     #984263336
          HierarchyParent     #btnGrpView
          Text                #@SYS119149
          ButtonDisplay       #Text & Image above
          NormalImage         #1044
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          Primary             #Yes
          DataSource          #UserInfo
          MenuItemName        #SysUserSetup
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mnuItBtnProfiles
          AutoDeclaration     #Yes
          ElementPosition     #1811939326
          HierarchyParent     #btnGrpView
          Text                #@SYS343149
          ButtonDisplay       #Text & Image above
          NormalImage         #10959
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          Primary             #Yes
          NeedsRecord         #Yes
          DataSource          #UserInfo
          MenuItemName        #Profiles
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mnuItBtnRelations
          AutoDeclaration     #Yes
          ElementPosition     #1476395006
          HierarchyParent     #btnGrpView
          Text                #@SYS80613
          ButtonDisplay       #Text & Image above
          NormalImage         #10056
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Big                 #Yes
          Primary             #Yes
          DataSource          #UserInfo
          MenuItemName        #SysCompanyUserInfo
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL MENUITEMBUTTON
        PROPERTIES
          Name                #mnuItmBtnEditInGrid
          AutoDeclaration     #Yes
          ElementPosition     #1849222027
          HierarchyParent     #btnGrpMaintain
          Text                #@SYS319303
          ButtonDisplay       #Text & Image above
          NormalImage         #10011
          ImageLocation       #EmbeddedResource
          ShowShortCut        #No
          Primary             #Yes
          DataSource          #UserInfo
          OpenMode            #Edit
          CopyCallerQuery     #Yes
          FormViewOption      #Grid
          MenuItemName        #SysUserInfoPageEdit
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL STRINGEDIT
        PROPERTIES
          Name                #UserEmail
          AutoDeclaration     #Yes
          Visible             #No
          AllowEdit           #No
          ElementPosition     #2143289342
          HierarchyParent     #Grid
          ExtendedDataType   
            ARRAY
              #Email
              #
            ENDARRAY
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL STRINGEDIT
        PROPERTIES
          Name                #UserInfo_Company
          Width               #56
          HelpText            #@SYS81122
          ElementPosition     #2105540606
          HierarchyParent     #Grid
          Label               #@SYS13342
          DataSource          #UserInfo
          DataField           #company
        ENDPROPERTIES
       
        METHODS
          SOURCE #lookup
            #public void lookup()
            #{
            #    Query                query;
            #    QueryBuildDataSource dataAreaDS;
            #    QueryBuildDataSource filterDS;
            #    QueryBuildRange      range;
            #
            #    SysTableLookup sysTableLookup;
            #    SecurityRights rights;
            #
            #    if (!userInfo.RecId)
            #    {
            #        // User doe not exist yet;
            #        // show all companies.
            #        super();
            #    }
            #    else
            #    {
            #        // Populated UserDataAreaFilter
            #        // with list of selectble companies
            #        rights = SecurityRights::newUser(userInfo.Id);
            #        rights.populateSelectableCompanies();
            #
            #        // Initialize table lookup
            #        // and add fields to be shown in the lookup form.
            #        sysTableLookup = SysTableLookup::newParameters(tableNum(DataArea), this);
            #        sysTableLookup.addLookupfield(fieldNum(DataArea, Id));
            #        sysTableLookup.addLookupfield(fieldNum(DataArea, Name));
            #
            #        // Build the query...
            #        // select Id, Name from DataArea A
            #        // exists join UserDataAreaFilter B
            #        // on A.Id = B.DataArea
            #        // where B.User == <UserId>
            #        query = new Query();
            #        dataAreaDS = query.addDataSource(tableNum(DataArea));
            #        range = dataAreaDS.addRange(fieldNum(DataArea, IsVirtual));
            #        range.status(RangeStatus::Hidden);
            #        range.value(SysQuery::value(false));
            #
            #        filterDS = dataAreaDS.addDataSource(tableNum(UserDataAreaFilter));
            #        filterDS.relations(true);
            #        range = filterDS.addRange(fieldNum(UserDataAreaFilter, User));
            #        range.status(RangeStatus::Hidden);
            #        range.value(SysQuery::value(userInfo.Id));
            #
            #        // Set the query and perform the lookup.
            #        sysTableLookup.parmQuery(query);
            #        sysTableLookup.performFormLookup();
            #
            #        // Don't call super()
            #        // super()
            #    }
            #}
          ENDSOURCE
        ENDMETHODS
      ENDCONTROL
     
      CONTROL STRINGEDIT
        PROPERTIES
          Name                #UserInfo_Id
          AutoDeclaration     #Yes
          Width               #50
          ElementPosition     #2013265918
          HierarchyParent     #Grid
          Label               #@SYS4517
          DataSource          #UserInfo
          DataField           #id
        ENDPROPERTIES
       
        METHODS
        ENDMETHODS
      ENDCONTROL
     
      CONTROL STRINGEDIT
        PROPERTIES
          Name                #UserInfo_Name
          AutoDeclaration     #Yes
          ElementPosition     #2080374782
          HierarchyParent     #Grid
          DataSource          #UserInfo
          DataField           #name
        ENDPROPERTIES
       
        METHODS
          SOURCE #gotFocus
            #public void gotFocus()
            #{
            #    super();
            #    nameText = this.text();
            #}
          ENDSOURCE
          SOURCE #textChange
            #public void textChange()
            #{
            #    str usrId;
            #    usrId = userInfo.Id;
            #    if(!inNameTextChange && usrId == #GuestUser)
            #    {
            #        inNameTextChange = true;
            #        this.text('');
            #        inNameTextChange = false;
            #    }
            #}
          ENDSOURCE
        ENDMETHODS
      ENDCONTROL
     
      CONTROL STRINGEDIT
        PROPERTIES
          Name                #UserInfo_NetworkAlias
          AutoDeclaration     #Yes
          HelpText            #@SYS344941
          ElementPosition     #1431655763
          HierarchyParent     #Grid
          Label               #@SYS344940
          DataSource          #UserInfo
          DataField           #networkAlias
        ENDPROPERTIES
       
        METHODS
          SOURCE #gotFocus
            #public void gotFocus()
            #{
            #    super();
            #    aliasText = this.text();
            #    aliasUserId = userInfo.Id;
            #    enabledOnce = userInfo.EnabledOnce;
            #}
          ENDSOURCE
          SOURCE #modified
            #public boolean modified()
            #{
            #    boolean ret;
            #
            #    Name alias;
            #    str initUserId;
            #
            #    ret = super();
            #
            #    alias = this.text();
            #
            #    // If the user id is not entered and alias is entered, generated a 5 character user id and update the grid
            #    if(alias != '' && userInfo.Id == '')
            #    {
            #        initUserId = element.generateInitialUserId(alias);
            #
            #        if(initUserId != '')
            #        {
            #            userInfo.Id = initUserId;
            #        }
            #    }
            #
            #    return ret;
            #}
            #
          ENDSOURCE
          SOURCE #textChange
            #public void textChange()
            #{
            #    str usrId;
            #    usrId = userInfo.Id;
            #
            #    if(!inAliasTextChange && usrId == aliasUserId)
            #    {
            #        if(((aliasText != '' && usrId != #AdminUser)  && enabledOnce) || (usrId == #GuestUser))
            #        {
            #            inAliasTextChange = true;
            #            this.text(aliasText);
            #            inAliasTextChange = false;
            #        }
            #    }
            #}
            #
          ENDSOURCE
        ENDMETHODS
      ENDCONTROL
     
      CONTROL STRINGEDIT
        PROPERTIES
          Name                #UserInfo_NetworkDomain
          AutoDeclaration     #Yes
          ElementPosition     #1879048190
          HierarchyParent     #Grid
          Label               #@SYS89981
          DataSource          #UserInfo
          DataField           #networkDomain
        ENDPROPERTIES
       
        METHODS
          SOURCE #gotFocus
            #public void gotFocus()
            #{
            #    super();
            #    domainText = this.text();
            #    domainUserId = userInfo.Id;
            #    enabledOnce = userInfo.EnabledOnce;
            #}
          ENDSOURCE
          SOURCE #textChange
            #public void textChange()
            #{
            #    str usrId;
            #    usrId = userInfo.Id;
            #
            #    if(!inDomainTextChange && usrId == domainUserId)
            #    {
            #        if(((domainText != '' && usrId != #AdminUser)  && enabledOnce) || (usrId == #GuestUser))
            #        {
            #            inDomainTextChange = true;
            #            this.text(domainText);
            #            inDomainTextChange = false;
            #        }
            #    }
            #}
          ENDSOURCE
        ENDMETHODS
      ENDCONTROL
     
    ENDCONTAINER
   
  ENDDESIGN
 
  PERMISSIONS #Permissions
    PROPERTIES
    ENDPROPERTIES
   
    PERMISSIONSET #Read
      PROPERTIES
      ENDPROPERTIES
     
      FORM #Controls
      ENDFORM
     
    TABLES #Tables
    ENDTABLES
   
  SERVERMETHODS #Server Methods
  ENDSERVERMETHODS
 
ASSOCIATEDFORMS #Associated Forms
  ASSOCIATEDFORM #SysUserInfoDetail
    PROPERTIES
      Form                #SysUserInfoDetail
      AccessLevel         #Read
      SystemManaged       #No
      ManagedBy           #Manual
    ENDPROPERTIES
   
  ENDASSOCIATEDFORM
 
ENDASSOCIATEDFORMS
ENDPERMISSIONSET
PERMISSIONSET #Update
  PROPERTIES
  ENDPROPERTIES
 
  FORM #Controls
  ENDFORM
 
TABLES #Tables
ENDTABLES
SERVERMETHODS #Server Methods
ENDSERVERMETHODS
ASSOCIATEDFORMS #Associated Forms
  ASSOCIATEDFORM #SysUserInfoDetail
    PROPERTIES
      Form                #SysUserInfoDetail
      AccessLevel         #Update
      SystemManaged       #No
      ManagedBy           #Manual
    ENDPROPERTIES
   
  ENDASSOCIATEDFORM
 
ENDASSOCIATEDFORMS
ENDPERMISSIONSET
PERMISSIONSET #Create
  PROPERTIES
  ENDPROPERTIES
 
  FORM #Controls
  ENDFORM
 
TABLES #Tables
ENDTABLES
SERVERMETHODS #Server Methods
ENDSERVERMETHODS
ASSOCIATEDFORMS #Associated Forms
  ASSOCIATEDFORM #SysUserInfoDetail
    PROPERTIES
      Form                #SysUserInfoDetail
      AccessLevel         #Create
      SystemManaged       #No
      ManagedBy           #Manual
    ENDPROPERTIES
   
  ENDASSOCIATEDFORM
 
ENDASSOCIATEDFORMS
ENDPERMISSIONSET
PERMISSIONSET #Delete
  PROPERTIES
  ENDPROPERTIES
 
  FORM #Controls
  ENDFORM
 
TABLES #Tables
ENDTABLES
SERVERMETHODS #Server Methods
ENDSERVERMETHODS
ASSOCIATEDFORMS #Associated Forms
  ASSOCIATEDFORM #SysUserInfoDetail
    PROPERTIES
      Form                #SysUserInfoDetail
      AccessLevel         #Delete
      SystemManaged       #No
      ManagedBy           #Manual
    ENDPROPERTIES
   
  ENDASSOCIATEDFORM
 
ENDASSOCIATEDFORMS
ENDPERMISSIONSET
ENDPERMISSIONS
ENDFORM

***Element: FTM
; Microsoft Dynamics AX MENUITEM : ABH_UserattachedwithRole unloaded
; --------------------------------------------------------------------------------
  VERSION 1
 
  MENUITEM #ABH_UserattachedwithRole
    Type: 3
    PROPERTIES
      Name                #ABH_UserattachedwithRole
      Label               #Users attached with role
      ObjectType          #Class
      Object              #ABH_UserattachedwithRole
      Origin              #{F448E8E4-D3A1-425F-9142-6ADD1D1596E7}
    ENDPROPERTIES
   
  ENDMENUITEM
 
***Element: CLS
; Microsoft Dynamics AX Class: ABH_UserattachedwithRole unloaded
; --------------------------------------------------------------------------------
  CLSVERSION 1
 
  CLASS #ABH_UserattachedwithRole
    PROPERTIES
      Name                #ABH_UserattachedwithRole
      Extends             #RunBase
      Origin              #{65BBF18F-70FD-4A7F-998F-F82399D8BEF4}
    ENDPROPERTIES
   
    METHODS
      SOURCE #organizationId
        #//BP Deviation documented
        #public OMOperatingUnitNumber organizationId(OMUserRoleOrganization _org)
        #{
        #    CompanyInfo company;
        #    OMOperatingUnit operatingUnit;
        #
        #    select firstonly RecId, DataArea from company where company.RecId == _org.omInternalOrganization;
        #    if (company)
        #        return company.DataArea;
        #
        #    select firstonly RecId, omOperatingUnitNumber from operatingUnit where operatingUnit.RecId == _org.omInternalOrganization;
        #    if (operatingUnit)
        #        return operatingUnit.omOperatingUnitNumber;
        #
        #    return '';
        #}
      ENDSOURCE
      SOURCE #classDeclaration
        #class ABH_UserattachedwithRole extends runbase
        #{
        #    SecurityRoleAotName     securityRoleAotName;
        #
        #    DialogRunbase           dialog;
        #    DialogField             dialogsecurityRoleAotName;
        #
        #    UserId                  userId;
        #
        #    //container               grouplist;
        #    Map                     groupUserMapValue;
        #    MapIterator             groupMapIterator;
        #
        #    SysExcelApplication excel;
        #    SysExcelWorkbooks   workbooks;
        #    SysExcelWorkbook    workbook;
        #    SysExcelWorksheets  worksheets;
        #    SysExcelWorksheet   worksheet;
        #    SysExcelCells       cells;
        #    SysExcelCell        cell;
        #    int                 row;
        #}
      ENDSOURCE
      SOURCE #dialog
        #protected Object dialog()
        #{
        #    dialog = super();
        #
        #    dialogsecurityRoleAotName = dialog.addField(identifierStr(SecurityRoleAotName));
        #
        #    return dialog;
        #}
      ENDSOURCE
      SOURCE #getFromDialog
        #public boolean getFromDialog()
        #{
        #    securityRoleAotName = dialogsecurityRoleAotName.value();
        #
        #    return true;
        #}
      ENDSOURCE
      SOURCE #insertheader
        #private void insertheader()
        #{
        #    excel       = SysExcelApplication::construct();
        #    workbooks   = excel.workbooks();
        #    workbook    = workbooks.add();
        #    worksheets  = workbook.worksheets();
        #    worksheet   = worksheets.itemFromNum(1);
        #
        #    cells = worksheet.cells();
        #    cells.range('A:A').numberFormat('@');
        #
        #    cell = cells.item(row+1, 1);
        #    cell.value('User id');
        #
        #    cell = cells.item(row+1, 2);
        #    cell.value('Alias');
        #
        #    cell = cells.item(row+1, 3);
        #    cell.value('User group');
        #
        #    cell = cells.item(row+1, 4);
        #    cell.value('Role assigned - Aot Name');
        #
        #    cell = cells.item(row+1, 5);
        #    cell.value('Role assigned - Name');
        #
        #    cell = cells.item(row+1, 6);
        #    cell.value('Role assigned - Description');
        #
        #    cell = cells.item(row+1, 7);
        #    cell.value('Company assigned to');
        #}
      ENDSOURCE
      SOURCE #pack
        #public container pack()
        #{
        #    return conNull();
        #}
      ENDSOURCE
      SOURCE #parmUserId
        #Public UserId parmUserId(UserId _userId = userId)
        #{
        #    userId = _userId;
        #
        #    return UserId;
        #}
      ENDSOURCE
      SOURCE #readmemberoffromUser
        #void readmemberoffromUser()
        #{
        #    InteropPermission                                   interopPermission;
        #    System.DirectoryServices.DirectorySearcher          directorySearcher, ds;
        #    System.DirectoryServices.DirectoryEntry             entry, obUser;
        #    System.DirectoryServices.SearchResultCollection     searchResultCollection, resCol;
        #    System.DirectoryServices.SearchScope                searchScope;
        #    System.DirectoryServices.SearchResult               searchResult, sr;
        #    System.DirectoryServices.PropertyCollection         propertyCollection, pc;
        #    System.DirectoryServices.PropertyValueCollection    propertyValueCollection, pvc;
        #    str                                                 company, st, mysamaccountname, userIdCon;
        #    str                                                 searchCriteria;
        #    int                                                 searchCount, i, length;
        #
        #    UserInfo userInfo;
        #    Counter counter, j;
        #
        #    boolean check = false;
        #    ;
        #
        #    groupUserMapValue   = new Map(Types::String, Types::String);
        #
        #    interopPermission = new InteropPermission(InteropKind::ClrInterop);
        #    interopPermission.assert();
        #
        #    while select * from userInfo
        #        where UserInfo.id   == userId
        #        && userInfo.accountType == UserAccountType::ADUser
        #    {
        #        try
        #        {
        #            searchScope = System.DirectoryServices.SearchScope::Subtree;
        #
        #            entry = new System.DirectoryServices.DirectoryEntry("LDAP://" + "AX2012R2A"); // Change to yours
        #
        #            directorySearcher = new System.DirectoryServices.DirectorySearcher(entry);
        #            directorySearcher.set_PageSize(65535);
        #            directorySearcher.set_CacheResults(false);
        #            directorySearcher.set_SearchScope(searchScope);
        #
        #            //usergroup
        #            searchCriteria = strFmt("(samaccountname=%1)", userInfo.networkAlias);
        #
        #            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('MemberOf');
        #
        #                    if (PropertyValueCollection)
        #                    {
        #                        if (propertyValueCollection.get_Count())
        #                        {
        #                            counter = propertyValueCollection.get_Count();
        #
        #                            for (j = 0; j < counter ; j++)
        #                            {
        #                                st = PropertyValueCollection.get_Item(j);
        #
        #                                obUser = new System.DirectoryServices.DirectoryEntry("LDAP://" + st);
        #                                ds = new System.DirectoryServices.DirectorySearcher(obUser);
        #                                resCol = ds.FindAll();
        #
        #                                sr = resCol.get_Item(0);
        #                                obUser = sr.GetDirectoryEntry();
        #                                if (obUser)
        #                                {
        #                                    pc = obUser.get_Properties();
        #                                    if (pc)
        #                                    {
        #                                        pvc = pc.get_Item('name');
        #                                        if(pvc)
        #                                        {
        #                                            mysamaccountname= pvc.get_Value();
        #
        #                                            userIdCon = userInfo.id + int2str(j);
        #
        #                                            groupUserMapValue.insert(userIdCon, mysamaccountname);
        #                                        }
        #                                    }
        #                                }
        #                            }
        #                        }
        #                    }
        #                }
        #            catch (Exception::CLRError)
        #            {
        #                SRSProxy::handleClrException(Exception::Warning);
        #                warning(strFmt("@SYS117734"));
        #            }
        #            entry.Dispose();
        #        }
        #        searchResultCollection.Dispose();
        #        check = true;
        #    }
        #    catch (Exception::CLRError)
        #    {
        #        SRSProxy::handleClrException(Exception::Warning);
        #        error("@SYS117735");
        #    }
        #
        #    CodeAccessPermission::revertAssert();
        #    }
        #    if(check == false)
        #    {
        #        throw error('Roles can be found for user only.');
        #    }
        #}
      ENDSOURCE
      SOURCE #rolesattacedonuserInfo
        #private void rolesattacedonuserInfo(UserId  _userGroupId)
        #{
        #    UserInfo                userInfoGroup, userInfo;
        #    SecurityRole            securityRole;
        #    SecurityUserRole        securityUserRole;
        #    OMUserRoleOrganization  userRoleOrganization;
        #
        #    str userIdLoc = userId;
        #    str orgId;
        #    str userGroup = _userGroupId;
        #
        #    boolean checked = false;
        #
        #    select firstOnly ID from userInfoGroup
        #        where userInfoGroup.networkAlias == _userGroupId;
        #
        #    select firstonly ID from userInfo
        #        where userInfo.id == userId;
        #
        #    while select User, SecurityRole from securityUserRole
        #        where securityUserRole.User == userInfoGroup.id
        #    {
        #        select firstOnly Name, AotName, Description, RecId from securityRole
        #            where securityRole.RecId == securityUserRole.SecurityRole;
        #
        #        if(row == 0)
        #        {
        #            this.insertheader();
        #        }
        #
        #        checked = false;
        #        while select userRoleOrganization
        #            where userRoleOrganization.SecurityRole == securityUserRole.SecurityRole
        #                && userRoleOrganization.User        == _userGroupId
        #        {
        #            row++;
        #            cell = cells.item(row+1, 1);
        #            cell.value(userIdLoc);
        #
        #            cell = cells.item(row+1, 2);
        #            cell.value(userInfo.networkAlias);
        #
        #            cell = cells.item(row+1, 3);
        #            cell.value(userGroup);
        #
        #            cell = cells.item(row+1, 4);
        #            cell.value(securityRole.AotName);
        #
        #            cell = cells.item(row+1, 5);
        #            cell.value(securityRole.Name);
        #
        #            cell = cells.item(row+1, 6);
        #            cell.value(securityRole.Description);
        #
        #            orgId = this.organizationId(userRoleOrganization);
        #
        #            cell = cells.item(row+1, 7);
        #            cell.value(orgId);
        #
        #            checked = true;
        #        }
        #
        #        if(checked == false)
        #        {
        #            row++;
        #            cell = cells.item(row+1, 1);
        #            cell.value(userIdLoc);
        #
        #            cell = cells.item(row+1, 2);
        #            cell.value(userInfo.networkAlias);
        #
        #            cell = cells.item(row+1, 3);
        #            cell.value(userGroup);
        #
        #            cell = cells.item(row+1, 4);
        #            cell.value(securityRole.AotName);
        #
        #            cell = cells.item(row+1, 5);
        #            cell.value(securityRole.Name);
        #
        #            cell = cells.item(row+1, 6);
        #            cell.value(securityRole.Description);
        #
        #            orgId = 'Access to all company';
        #
        #            cell = cells.item(row+1, 7);
        #            cell.value(orgId);
        #        }
        #    }
        #}
      ENDSOURCE
      SOURCE #run
        #public void run()
        #{
        #    this.readmemberoffromUser();
        #    this.validateValuefromAD();
        #}
      ENDSOURCE
      SOURCE #unpack
        #public boolean unpack(container packedClass)
        #{
        #    return true;
        #}
      ENDSOURCE
      SOURCE #validateValuefromAD
        #private void validateValuefromAD()
        #{
        #    NetworkAlias    userGroupId;
        #
        #    groupMapIterator = new MapIterator(groupUserMapValue);
        #    //this.insertheader();
        #    while(groupMapIterator.more())
        #    {
        #        userGroupId = groupMapIterator.value();
        #
        #        this.rolesattacedonuserInfo(userGroupId);
        #
        #        groupMapIterator.next();
        #    }
        #    excel.visible(true);
        #    info('Done');
        #}
      ENDSOURCE
      SOURCE #main
        #Public static void main(Args _args)
        #{
        #    UserInfo                    userInfo;
        #    ABH_UserattachedwithRole    userattachedwithRole = new ABH_UserattachedwithRole();
        #
        #    userInfo = _args.record();
        #
        #    userattachedwithRole.parmUserId(userInfo.id);
        #
        #    userattachedwithRole.run();
        #}
      ENDSOURCE
    ENDMETHODS
  ENDCLASS
***Element: PRN
; Microsoft Dynamics AX Project : ABH_UserattachedwithRole unloaded
; --------------------------------------------------------------------------------
  PROJECTVERSION 2
 
  PROJECT #ABH_UserattachedwithRole
  SHARED
  PROPERTIES
    Name                #ABH_UserattachedwithRole
    Origin              #{0E3A0C1C-31EC-4A1E-8940-0CAD6B948F28}
  ENDPROPERTIES
 
    PROJECTCLASS ProjectNode
    BEGINNODE
      FILETYPE 0
      UTILTYPE 11
      UTILOBJECTID 0
      NODETYPE 201
      NAME #SysUserInfoPage
    ENDNODE
    BEGINNODE
      FILETYPE 0
      UTILTYPE 3
      UTILOBJECTID 0
      NODETYPE 296
      NAME #ABH_UserattachedwithRole
    ENDNODE
    BEGINNODE
      FILETYPE 0
      UTILTYPE 45
      UTILOBJECTID 1036542
      NODETYPE 329
      NAME #ABH_UserattachedwithRole
    ENDNODE
  ENDPROJECT
 
***Element: END