Dynamics AX Blog - Page 7

These posts are machine-translated.

SysOperation Framework: Simple class construct with data provider

The code below is a simple class construct for the SysOperation framework.

Datacontract

[DataContractAttribute]
public class TutorialSysOperationDataContract
{
    CustAccount custAccount;
}

 

[DataMemberAttribute]
public CustAccount parmCustAccount(CustAccount _custAccount = custAccount)
{
    custAccount = _custAccount;
    return custAccount;
}

 

Service

class TutorialSysOperationService extends SysOperationServiceBase
{
}

The method runService() is the actual service method. Using the SysEntryPointAttribute attribute, we control here that no further authorization checks are necessary.

[SysEntryPointAttribute(false)]
public void runService(TutorialSysOperationDataContract _dataContract)
{
    info("Done");
}

 
 

SysOperation-Framework: Simple class construct

The following code shows a very simple class construct for the SysOperation framework. Without the Dataprovider and UIBuilder.

Service

class TutorialSysOperationService extends SysOperationServiceBase
{
}

The method runService() is the actual service method. By means of the attribute SysEntryPointAttribute we control here that no further authorization checks are necessary.

[SysEntryPointAttribute(false)]
public void runService()
{
    info("Done");
}

 

Controller

class TutorialSysOperationController extends SysOperationServiceController
{
}

In the new()-method, we link the controller to the service class.

void new()
{
    super();

    this.parmClassName(classStr(TutorialSysOperationService));
    this.parmMethodName(methodStr(TutorialSysOperationService, runService));
}

The main()-method is the classic entry point when the controller is called via a MenuItem.

public static void main(Args _args)
{
    TutorialSysOperationController controller;

    controller = new TutorialSysOperationController();
    controller.parmArgs(_args);

    controller.parmExecutionMode(SysOperationExecutionMode::Synchronous);

    controller.startOperation();
}

 
 

Create shared project by code, add objects and create groups for each object type

With the help of the job shown here, you can create a shared project by code, add objects and group them into groups per object type.

static void AddNodeToSharedProject(Args _args)
{
    projectNode projectNode;
    TreeNode treeNode;
    ProjectName projectName = "MyProject";
    
    #AOT
    #AOTExport
    
    void addTreeNodeToProjectNode(treeNode _treeNode)
    {
        TmpIdRef tmpIdRef;
            
        tmpIdRef.clear();
        tmpIdRef.Name = SysTreeNode::getPath(_treeNode);
        tmpIdRef.Mode = SysTreeNode::path2ApplObjectType(tmpIdRef.Name);
        tmpIdRef.useMode = UtilFileType::Application;
        tmpIdRef.insert();
        
        SysProjectFilterRunBase::addProjectNodes(tmpIdRef, projectNode);           
    }

    projectNode    = infolog.projectRootNode();
    projectNode    = projectNode.AOTfindChild(#expProjectShared);
    projectNode    = projectNode.AOTfindChild(projectName);
   
    // Create shared project if neccessary
    if( !projectNode)
    {
        projectNode = SysTreeNode::createProject(projectName, ProjectSharedPrivate::ProjShared);        
    }
    
    // Add objects (and create groups)
    treenode = TreeNode::findNode(#TablesPath+#AOTRootPath+tableid2name(tablenum(AccountingDistribution)));
    addTreeNodeToProjectNode(treenode);

    treenode = TreeNode::findNode(#TablesPath+#AOTRootPath+tableid2name(tablenum(VendGroup)));
    addTreeNodeToProjectNode(treenode);
   
    treenode = TreeNode::findNode(#ClassesPath+#AOTRootPath+classStr(PriceDisc));
    addTreeNodeToProjectNode(treenode);

}

In the same way you can also create a private project, simply replace the occurrences of Shared by Private.

The created project looks like this:

Sceenshot


 
 

SysOperation-Framework: Asynchronous processing

The SysOperation framework can also be used to execute functions asynchronously. For this, the ExecutionMode is set to SysOperationExecutionMode::Asynchronous.

This makes sense, for example, when a time-intensive action is to be started, but the user does not have to wait for the end of this action and has to be able to continue working on other topics.

However, such asynchronous processing only works if the following criteria are met:

  • The function was integrated as a service
  • This service has been added to the AxClient service group
  • The user has activated the Run Business Operations into CIL option

 
 

CreateNavigationPropertyMethods

Ever seen in the code the call of the method product() of an InventTable instance and wondered where this method comes from and why you can not see it?

inventTable.product()

This method is created by using the property CreateNavigationPropertyMethods of a (foreign key) relation.

Via the property NavigationPropertyMethodNameOverride of the relation you can also change the name of the created method, if needed.

Screenshot AOT


 
 

Merge two maps into one

Recently, I wanted to merge two maps into one, but I did not find an appropriate function, so I wrote the following myself.

private Map mergeMaps(Map _map1, Map _map2)
{
    Map retMap;
    MapEnumerator mapEnum;
    // Initate first map from second map if empty
    if( !_map1)
    {
        _map1 = new Map(_map2.keyType(), _map2.valueType());
    }
    // Check compatibility
    if(_map1 && _map2)
    {
        if(_map1.keyType() != _map2.keyType() || _map1.valueType() != _map2.valueType())
        {
            throw error(Error::wrongUseOfFunction(funcName()));
        }
    }

    retMap = _map1;
    mapEnum = _map2.getEnumerator();
    while(mapEnum.moveNext())
    {
        if( !retMap.exists(mapEnum.currentKey()))
        {
            retMap.insert(mapEnum.currentKey(), mapEnum.currentValue());
        }
    }
    return retMap;
}

 
 

Use the PreviewPartRef property of a table

Preview partHave you ever wondered how Dynamics AX builds up this window for employees when moving the mouse over the name of an employee?

This is caused by the PreviewPartRef property of a table, which allows you to quickly create preview windows.

The following steps are necessary:

  • Create a form
  • Create a form part, which points to above form
  • Create a (Display-)Menu item which points to the form part
  • Enter the name of the menu item in the poperty PreviewPartRef of the table

For example, I created a simple form for the CustGroup table and included it as described above.

Enhanced preview part

Without my customization, the preview usually looks as follows:

Original previw part
 


 
 
Pages « 1 ... 4 5 6 7 8 9 10 ... 24 » 

 

 
 
 
Posts of the actual month
April 2024
MoTuWeThFrSaSu
1234567
891011121314
15161718192021
22232425262728
2930 
 
© 2006-2024 Heinz Schweda | Imprint | Contact | German version | Mobile version
In order to provide you with better service, this site uses cookies. By continuing to browse the site, you are agreeing to our use of cookies.