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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

How to initialize parameters in sys operations?

(0) ShareShare
ReportReport
Posted on by 252

Hi,

I want to initialize some default parameters in sys operation in run time before the UI interface is displayed to the user. Could someone please let me know where and how to pass the contract parameters to set the values?

Thanks!!

*This post is locked for comments

I have the same question (0)
  • Martin Dráb Profile Picture
    237,924 Most Valuable Professional on at

    It depends on what exactly you're trying to achieve. Maybe you should simply let your contract implement SysOperationInitializable interface (possibly with SysOperationAlwaysInitializeAttribute).

    If it's not possible, you should do it through a controller class (and it's different for report controllers and general-purpose controllers).

  • Suren_G Profile Picture
    252 on at

    Hi Martin,

    The below is what I am trying to do exactly.

    This is for general sysoperation controller(not report controller). Whenever the user clicks on the menuitem, the parameter has certain checkboxes which needs to be checked before the UI is displayed to the user.

    I have tried in 'initParmDefault' in controller class. But it is not working. Please let me know if you do have any suggestions.

    Thanks!

  • Verified answer
    Martin Dráb Profile Picture
    237,924 Most Valuable Professional on at

    I already did (except of some typos I had there).

    Open your contract class, add implements SysOperationInitializable in class declaration and then add public void initialize() method. There implement your initialization logic.

    If you want the framework to call the method every time (instead of using values from the last run), decorate the class with SysOperationAlwaysInitializeAttribute.

  • Suggested answer
    Suren_G Profile Picture
    252 on at

    Hi Martin,

    I have added initialize() in the contract class by implementing SysOperationInitializable.. It works.. Thanks!!

  • Suren_G Profile Picture
    252 on at

    Hi Martin,

    One issue is that the initialize() hits only for the first run when I open the menu item. It is not hitting again until the user data is reset. Any suggestion pls!

  • Martin Dráb Profile Picture
    237,924 Most Valuable Professional on at

    Please read my answer again, especially the last sentence of my second reply.

  • Suren_G Profile Picture
    252 on at

    Yes. I tried by extending SysOperationAlwaysInitializeAttribute class in contract. initialize() doesn't hits.!

  • Verified answer
    Martin Dráb Profile Picture
    237,924 Most Valuable Professional on at

    Aha, I see, you don't know how to use attributes.

    To apply an attribute to a class (or "to decorate a class with an attribute"), put the attribute name in [ ] just above the class header in classDeclaration node. For example, this is how you apply DataContractAttribute:

    [DataContractAttribute]
    public class MyContract 

    In your case, you'll want to apply two attributes:

    [DataContractAttribute, SysOperationAlwaysInitializeAttribute]
    public class MyContract

    If you used cross-references on SysOperationAlwaysInitializeAttribute, you would easily find a plenty of example how to use it.

    You would extend an attribute class if you're creating a specialized attribute; that's clearly not your intention here.

  • Shaun Brady Profile Picture
    112 on at

    Good Morning Martin,

    I'm quite new to attributes also.

    The below example should have the two parameters always initialized each time the class is called?

    It doesn't seem to have made any difference for me. I'm still trying to explore why, but any additional help or advice would be greatly appreciated.

    I noticed in another post, you talk about implementing SysOperationInitializable(which I am researching now), but SysOperationAlwaysInitializeAttribute seems like a far better option for my case anyway.

    Thanks.

    [DataContractAttribute, SysOperationAlwaysInitializeAttribute]

    public class SysOperationDataContractClass
    {
    TransDate dateValue;
    Description255 textValue;
    }

  • Shaun Brady Profile Picture
    112 on at

    I have SysOperationInitializable working satisfactorily, I will stick with this until I have more time to understand and figure out why SysOperationAlwaysInitializeAttribute  doesn't want to play

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Martin Dráb Profile Picture

Martin Dráb 4 Most Valuable Professional

#1
Priya_K Profile Picture

Priya_K 4

#3
MyDynamicsNAV Profile Picture

MyDynamicsNAV 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans