web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

Data contract object not initialized

(0) ShareShare
ReportReport
Posted on by

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,

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    239,880 Most Valuable Professional on at

    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).

  • Community Member Profile Picture
    on at

    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!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Women in Power Builds Momentum

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders

These are the community rock stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
CP04-islander Profile Picture

CP04-islander 10

#2
Harisgillani Profile Picture

Harisgillani 4

#2
dserp Profile Picture

dserp 4

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans