Skip to main content

Notifications

Announcements

No record found.

Microsoft Dynamics AX forum
Answered

Data contract object not initialized

Posted on by Microsoft Employee

Hi,

I have written a SysOperationServiceController class and getting the following error whenever i run it.

HU_DataContract object not initialized.

Stack trace

(C)\Classes\HU_CustTesterServiceController\newFromArgs - line 25
(C)\Classes\HU_CustTesterServiceController\main - line 6

I am not sure what is missing, following is the code for the class 

class HU_CustTesterServiceController extends SysOperationServiceController
{
}

public static void main(Args _args)
{
   HU_CustTesterServiceController hu_CustTesterServiceController;
    ;

   hu_CustTesterServiceController  = HU_CustTesterServiceController::newFromArgs(_args);
   hu_CustTesterServiceController.startOperation();

}

public static HU_CustTesterServiceController newFromArgs(Args _args)
{
    HU_CustTesterServiceController    HU_CustTesterServiceController;
    HU_DataContract _HU_DataContract;
    CustTable   custTable;
    Query       query;
    IdentifierName className, methodName;
    SysOperationExecutionMode executionMode;


    [className, methodName, executionMode] = SysOperationServiceController::parseServiceInfo(_args );

    // create a new instance of the controller

   HU_CustTesterServiceController = new HU_CustTesterServiceController( className, methodName, executionMode);
    // initialize from args
    // one of the things this will do is read the "parameters" property from the menu item
    HU_CustTesterServiceController.initializeFromArgs(_args);

    // get datacontract
    // the string should be the same as the parameter name!

   _HU_DataContract =  HU_CustTesterServiceController.getDataContractObject('_HU_DataContract');
    // default current date
 _HU_DataContract.parmDate(systemDateGet());


    // check if the record is of type CustTable
    if(_args && _args.dataset() == tableNum(CustTable))
    {
        // cast record
        custTable = _args.record();

        // create new query
        query = new query(queryStr(HU_ForCustomers));
        // add range
        query.dataSourceTable(tableNum(CustTable)).addRange(fieldNum(CustTable, AccountNum)).value(queryValue(custTable.AccountNum));

        // set query on datacontract
    _HU_DataContract.setQuery(query);

    }


    // return a new instance of this controller
    return HU_CustTesterServiceController;
}

Many thanks,

  • Community Member Profile Picture
    Community Member Microsoft Employee on at
    RE: Data contract object not initialized

    The issue was resolved by clearing the cache but thanks for letting me know the proper way. I will try it by implementing SysOperationInitializable.

    Thanks!

  • Verified answer
    Martin Dráb Profile Picture
    Martin Dráb 228,089 Super User 2024 Season 2 on at
    RE: Data contract object not initialized

    It seems that line 25 is the call of parmDate(). It fails you're getting the contract from getDataContractObject() without initializing it first.

    You could initialize the contract by yourself, but a better strategy will be putting your code at the right place. One possibility is doing it in prePromptModifyContract() or preRunModifyContract() instead in main(). Nevertheless the date you set don't depend on any inputs from the caller, so you can simply do it in the data contract class (after implementing SysOperationInitializable; you can also apply SysOperationAlwaysInitializeAttribute).

Helpful resources

Quick Links

Dynamics 365 Community Update – Sep 9th

Welcome to the next edition of the Community Platform Update. This is a weekly…

Announcing Our 2024 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for the daily…

Leaderboard

#1
André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 290,252 Super User 2024 Season 2

#2
Martin Dráb Profile Picture

Martin Dráb 228,089 Super User 2024 Season 2

#3
nmaenpaa Profile Picture

nmaenpaa 101,148

Leaderboard

Featured topics

Product updates

Dynamics 365 release plans