web
You’re offline. This is a read only version of the page.
close
Skip to main content
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)
  • Suggested answer
    Eugen Glasow Profile Picture
    6,359 on at
    RE: How to initialize parameters in sys operations?

    The suggestion made by Martin works just fine in standalone customizations.

    Yet it may not be applicable to contract extensions, unless the extended base class was implementing SysOperationInitializable. My solution is dumb as a brick: use a default value for the class variable:

    [ExtensionOf(ClassStr(AssetRollForwardContract))]
    final class EGCAssetRollForwardContract_Extension
    {
    private boolean calculateDepreciationInfo = true;

    ...


    Surprisingly, it works.

  • Martin Dráb Profile Picture
    236,039 Most Valuable Professional on at
    RE: How to initialize parameters in sys operations?

    MSandy, I replied to your specific question in your thread Initialize contract parameters for recurrence batch job in SysOperationFramework. Please continue the discussion there if needed.

  • MSandy Profile Picture
    219 on at
    RE: How to initialize parameters in sys operations?

    My code is like this:

    [DataContractAttribute, SysOperationAlwaysInitializeAttribute]

    public class DataContract implements SysOperationInitializable

    {

    public void initialize()

       {

           fromDate    = prevQtr(DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone()));

           toDate      = DateTimeUtil::getSystemDate(DateTimeUtil::getUserPreferredTimeZone());

       }

    }

  • MSandy Profile Picture
    219 on at
    RE: How to initialize parameters in sys operations?

    Hello Martijn,

    I have a contract class where i am initializing the "from date" and "to Date" by implementing sysOperationInitializable. I decorated my contract class with SysOperationAlwaysInitializeAttribute. when i manually run the batch job, contract taking newly initialized values but when i add this to a Batch Job with recurrence it is not taking the initialized values instead running with the same contract values every time.

    could you please help me what is the issue?

    Thanks,

    Sandeep

  • Emranee Profile Picture
    80 on at
    RE: How to initialize parameters in sys operations?

    Looks like you need to generate incremental CIL to take effect.

  • Suggested answer
    Martin Dráb Profile Picture
    236,039 Most Valuable Professional on at
    RE: How to initialize parameters in sys operations?

    If you read my first reply in this thread, you'll see that I mentioned SysOperationInitializable there too and I said that SysOperationAlwaysInitializeAttribute is optional.

    There are two steps.

    First you need your initialization logic, which is done by implementing SysOperationInitializable.

    But it doesn't mean that initialization is called every time. If you run the process for the second time, it will likely use parameters from the previous execution and the initialization will be skipped. If you want to enforce it, SysOperationAlwaysInitializeAttribute will help you.

  • Shaun Brady Profile Picture
    112 on at
    RE: How to initialize parameters in sys operations?

    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

  • Shaun Brady Profile Picture
    112 on at
    RE: How to initialize parameters in sys operations?

    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;
    }

  • Verified answer
    Martin Dráb Profile Picture
    236,039 Most Valuable Professional on at
    RE: How to initialize parameters in sys operations?

    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.

  • Suren_G Profile Picture
    252 on at
    RE: How to initialize parameters in sys operations?

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

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…

Andrés Arias – Community Spotlight

We are honored to recognize Andrés Arias as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 2

#1
Martin Dráb Profile Picture

Martin Dráb 2 Most Valuable Professional

#1
Guy Terry Profile Picture

Guy Terry 2 Moderator

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans