Dynamics AX Blog - Page 8

These posts are machine-translated.

Mobile Device Portal: Simple field validation

For the first time, I had the requirement to implement a simple field validation in the Mobile Device Portal (MDP). After I have tried something with the WHSWorkExecute class, I have found the class method WHSRFControlData.processData() as well suited for such type of exams.

Such an examination could look as follows:

case #Qty:
    qty = WHSWorkExecuteDisplay::str2numDisplay(data);
    if (qty <= 0)
    {
        errorMessage = "@WAX1172";
        hasError = true;
        break;
    }

    //--> Start
    if (pass.exists(#ProdId) &&
        pass.lookupStr(#ProdId) != "" &&
        mode == WHSWorkExecuteMode::ReportAsFinished)
    {
        my_ProdTable = ProdTable::find(pass.lookup(#ProdId));

        if (qty + my_ProdTable.reportedFinishedGood() +
            my_ProdTable.reportedFinishedError() > my_ProdTable.QtyStUp)
        {               
            errorMessage = "@SYS16097";
            hasError = true;
            break;
        }
    }           
    //<-- End

 
 

Sort Query by financial dimension

You can use the SysQuery::addOrderByDimensionAttribute() method to sort a query on a financial dimension.

The following example is intended to illustrate this. In this job, all customers are listed, sorted according to the dimension CostCenter.

static void sortByDimension(Args _args)
{
    Query query;
    QueryRun queryRun;
    QueryBuildDataSource qbds;
    CustTable custTable;
    DimensionComponent dimensionComponent;
    DimensionValue dimensionValue;

    #define.CostCenterDimensionName("CostCenter");

    query = new Query();
    qbds = query.addDataSource(tableNum(CustTable));

    SysQuery::addOrderByDimensionAttribute(query,
                                           qbds.name(),
                                           fieldId2name(tableNum(CustTable),
                                                        fieldNum(CustTable, DefaultDimension)),
                                           DimensionComponent::DimensionAttribute,
                                           SortOrder::Ascending,
                                           #CostCenterDimensionName);

    queryRun = new QueryRun(query);
    while(queryRun.next())
    {
        custTable = queryRun.get(tableNum(CustTable));

        // Get dimension value
        dimensionValue =
        (select firstonly DisplayValue from defaultDimensionView
         where defaultDimensionView.Name == #CostCenterDimensionName
            && defaultDimensionView.DefaultDimension == custTable.DefaultDimension).DisplayValue;

        info(strFmt("%1 %2", custTable.AccountNum, dimensionValue));
    }
}

 
 

Caching display methods

The fact that display methods should be cached, when they are used in forms, is well-known. For this, a corresponding call should always be integrated into the init() method of a form datasource:

public void init()
{
    super();
    this.cacheAddMethod(tableMethodStr(DirPartyPostalAddressView,locationRoles));
}

 

The fact that you can save this call in Dynamics AX 2012, if you set a corresponding attribute in the display method itself, was new to me:


 
 

Entitle SysOperation classes with the help of code Permissions

If you want to setup the security for a function, which is based on the Sysperation framework, by using a Code permission, the following steps are necessary:

  1. Create classes
  2. Create menu item (for Controller)
  3. Create Code Permission
  4. Add the method, which should be executed by the framework,  to the Server-Node of this code permission
  5. Add tables to Tables-Node if needed
  6. Change property LinkedPermissionObject to your Code Permission-object and property LnkedPermissionType to CodePermission of your above created menu item
  7. Add menu item to a privilege or a duty as needed

Picture: Step 4

Screenshot

More info at  MSDN.


 
 

Find missing labels in a specific language

Recently, I had to find out if a label exists in a certain language (in the example de_at), or not. Well suited for it seems the following SQL statement.

SELECT *
FROM [AX2012R3_TEST_model].[dbo].[ModelElementLabel] as existing
where existing.Module = 'myModule'
and existing.Language = 'en_us'
and not exists
( select *
from [AX2012R3_TEST_model].[dbo].[ModelElementLabel] as missing
where missing.labelid = existing.LabelId
and missing.Module = existing.Module
and missing.Language = 'de_at')

 
 

Detect/Respond on changing the edit mode

To respond in a form to change the edit mode, you can see the task () - Override method of the form as follows:

public int task(int _taskId)
{
    int ret;
    #Task
    ret = super(_taskId);
    
    switch(_taskId)
    {
        case #taskEditRecord:    
            …doSomething… 
            break;
    }
    return ret;
}

 

To get the current edit mode you may use the following method:

element.inViewMode()

 
 

Use special characters in the XML-header of a method

Sometimes you have to use special characters in the XML header of a method to document the code well. To get sure, that this header is still well-formed and is not identified as best practice deviation, you can use a CDATA section.

/// <version>
///  1.0
/// </version>
/// <summary>
/// <![CDATA[ Replaces following special characters: &, % ]]>
/// </summary>
private void someMethod()
{
    //...do something...
}

Without this CDATA section AX would spend the following BP-Deviation:

 

XML documentation is not well-formed.

 


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

 

 
 
 
Posts of the actual month
Mai 2024
MoTuWeThFrSaSu
 12345
6789101112
13141516171819
20212223242526
2728293031 
 
© 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.