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)

Adding method in form in ax 2012

(0) ShareShare
ReportReport
Posted on by

HI All,

I am trying to add a method to form dynamically, first i check if the method exists, if found i will delete that method and create new one, if not found i create new method simply. here is the code i am using. The following code is checking for the method existence and if not found its creating new method. BUT when method exists, it is not doing the way i wanted it simply stops and crashes the ax. please help me in correcting the following thanks in advance 

private void findOrCreateTimeStamp(
SysVersionControlTmpItem _item)
{
str timeStamp;
str methodSource;
UtilElements utilElement;
FormBuild formBuild;
MemberFunction method;
Object formRun;
Args args = new Args();
SysVersionControlTmpItem item = _item;
str methodName = "csGetVersion";
int time = timenow();
TreeNode treeNode = TreeNode::findNode(item.ItemPath);

utilElement = treeNode.utilElement();
timeStamp = date2Str(
today(),
321,
DateDay::Digits2,
DateSeparator::Slash,
DateMonth::Digits2,
DateSeparator::Slash,
DateYear::Digits4,
DateFlags::None);

timeStamp = timeStamp + "_" +
num2str0(time div 3600, 2, 0, 0, 0) + ":" +
num2Str0(time mod 3600 div 60, 2, 0, 0, 0) + ":" +
num2Str0(time mod 3600 mod 60, 2, 0, 0, 0);

methodSource = "public static str csGetVersion()\n{\n return '" +timeStamp+ "';\n}";

if (utilElement.recordType == UtilElementType::Form)
{
args.name(utilElement.name);

formRun = ClassFactory.formRunClass(args);
formBuild = new FormBuild(utilElement.name, true);

if (formHasMethod(formRun, methodName))
{
//Delete existing method and create new method here, since the method already exists in the component.
treeNode = formBuild.form().AOTfindChild('methods');
method = formBuild.form().AOTfindChild('methods').AOTfindChild(methodName);
method.AOTdelete();

formBuild.addMethod(
methodName,
methodSource);
}
else
{
//Make a new method here since it does'nt exist in the component.
formBuild.addMethod(
methodName,
methodSource);
}

formBuild.form().AOTcompile();
formBuild.form().AOTsave();
}
}

*This post is locked for comments

I have the same question (0)
  • Verified answer
    Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Adding method in form in ax 2012

    For reference, here is a link to another thread about the same/similar thing: Add dynamic method to a component in the AOT in ax 2012.

  • Verified answer
    syed baber Profile Picture
    11,633 on at
    RE: Adding method in form in ax 2012

    Hi Naga,

    Please have a look at following post. It may help you.

    community.dynamics.com/.../86650

    Thanks,

    Baber.

  • Community Member Profile Picture
    on at
    RE: Adding method in form in ax 2012

    I could not found the exact reason for crashing of AOS, but when i used non static method instead of static method to be added into form, it worked correctly. I think it was problem with adding static method and deleting it from the form, but not sure.

  • Martin Dráb Profile Picture
    236,394 Most Valuable Professional on at
    RE: Adding method in form in ax 2012

    Forms don't have static methods - you wouldn't have any way how to call them.

    That AX doesn't complain if you create a static method manually looks more like a bug than a feature.

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…

Abhilash Warrier – Community Spotlight

We are honored to recognize Abhilash Warrier as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Community Member Profile Picture

Community Member 4

#1
Martin Tocauer Profile Picture

Martin Tocauer 4

#3
Nayyar Siddiqi Profile Picture

Nayyar Siddiqi 2

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans