Question Status

Unanswered
saman0suke asked a question on 19 Feb 2013 3:15 PM

Hello, I have a form opened, then, open a second form from a different link, is there any way to set something like a timer, so, when this second form is closed, do something on the first one like clicking a button or something like that? is it possible? in C# I would user a thread or timer to evaluate that, but I don't know if it's possible in AX, thanks!

Reply
Martin Dráb responded on 20 Feb 2013 12:28 AM

You can create timer by Object.setTimeOut() method. But I wouldn't use timer in C# - an event subscription would make better sense. In AX, you would have to use object references and method calls instead events.

You wrote that the form is opened from a different link, but that doesn't prevent you from implementing a some way of notification. For example, both forms can inform a shared service when they start and end and the service can notify all others.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
saman0suke responded on 20 Feb 2013 6:15 AM

Well, basically, there are two buttons in form1, by using a third button, I click on button1 to perform a process, this opens a new form and leaves the parent one opened, I need to click on button2 on form1 when closing the newly opened form, is there any way to do it? can you give me more details about shared services in ax? thank you!

Reply
Martin Dráb responded on 20 Feb 2013 8:33 AM

If I understand what you say, you want to perform an action on the parent form when closing a child form. In that case, you can simply get a reference to the parent form by calling element.args().caller() on the child form. Then you can use the reference to invoke methods, which unfortunately requires to use weak-typing (with variable of Object type) - that's really bad for maintenance.
The better way may is to pass (via Args.caller() or Args.parmObject()) a reference to a class that knows how to perform the action and use it in strongly-typed way in the child form.

By shared services, I meant the general OO concept, not anything AX-specific. If the forms were run independently, without any parent-child relationship, they could still communicate through another well-known object (= service). It might be a simple singleton class, for example.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
saman0suke responded on 20 Feb 2013 8:54 AM

Well, it's something like that, however when I call element.args.caller() it recognizes a class, because the button on form1 calls an action MenuItem which calls this class and the class "creates" the form, so the parent is the class, not the form1 anymore, I'm working with SalesFormLetter and providing the params to a class would require a big debug process, is there any other way? thanks!

Reply
Martin Dráb responded on 20 Feb 2013 9:06 AM

You have a reference to the class and it has a reference to the form, so just ask the class and repeat the same thing once more (the class get Args in main()).

I also already described another way.

Try to think about it by yourself, I can only give you some building blocks.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply
saman0suke responded on 20 Feb 2013 9:35 AM

It's ok, you actually gave me some nice ideas, I'll give it a try and post my results! by the way, is there any way to have like a global get set variables so I can set them in a class, and get them in a different one? I've been using SysGlobalCache but I don't think is too recommended?or is it? thanks!

Reply
Martin Dráb responded on 20 Feb 2013 9:54 AM

Using SysGlobalCache is completely fine if you're aware that there are separate caches on client and server and - as with any global data - you're careful about not holding to much resources there. I use it myself for singletons.

Just don't use SysGlobalCache directly in consuming classes - encapsulate it in a separate class and let consumers use this class. How it is stored, what cache key is used etc. should be just an implementation detail.

Martin "Goshoom" Dráb | Freelancer | Goshoom.NET Dev Blog

Reply