Often enough, we need to restrict the user selection from a particular ComboBox. Creating a new BaseEnum specifically for this purpose is a really cumbersome solution, which later might lead to problems of maintenance.
Originally, the SysFormEnumComboBox was designed to be used on forms to provide for this behavior. I modified the class slightly to allow for usage in RunBase Framework classes.
To demonstrate, how this class can be used, I modified the tutorial_RunBaseForm class and form, showing both scenarios: adding the control from the dialog method of the class, as well as adding it manually in the form design and methods.
To use this class, you need to know only one static method:
public static SysFormEnumComboBox newParameters(
FormRun _formRun,
int _comboBoxControlId,
enumId _enumId,
Set _allowedEnumValuesSet,
Form _form = null)
And here is an example of how you would use it:
sysFormEnumComboBox = SysFormEnumComboBox::newParameters(element,
control::ComboBoxOnForm,
enumnum(InventTransType),
enumSet);
which means that the control ComboBoxOnForm will be bound to BaseEnum InventTransType, containing only values, found in the Set enumSet.
You can download the project for versions 4.0 and 2009 of Microsoft Dynamics AX through the following link:
download
P.S. It is also worth mentioning, that this class does not provide support for grids. It requires a stand-alone control, not bound to a database table field.
hi,
ReplyDeletethanks for ideas.
But I try similar things on form CustTable and didn't work:(.
Field Blocked from table CustTable is enum CustVendorBlocked extend about new 2 elements.
I want show only original elements +1 new.
At init method I use your way(seup at general tabpage AutodataGroup administration -> no and autodeclaration to yes.
btw. Did I understand correctly that this way is used only enum interval? exapmle I have 0,1,2,3,4 elements and only 0,1,2 range not 0,1,4?
Thank you very much for ideas
Martin Mikes
martin.mikes@circon.cz
What exactly did not work? Are you sure that you followed the guidelines correctly?
ReplyDeleteWhat AX version do you have?
The set of values you can use does not have to be sequential, so you can as well specify 0,1,4 as the range to display in the combo box.
If you export your xpo and send it to me, I might figure out what is wrong.
Or simply describe your problem in more details - what error message you get, or what behavior is incorrect?
I need to do that in a specific event. i.e. I have transaction main type and transaction subtype, when selecting a main type I want to filter the conbo to show specific fieds for each main type.
ReplyDeleteI tried it but it works only at the init event of the form.
thanks
I'm a AX beginner. Actually I don't know where should I start even no any book for reference!
ReplyDeleteI just go through with the website and search the limited info!
Any idea to guide me?
Thanks
Well, there is a number of books available on Dynamics AX nowadays.
ReplyDeleteIf you are interested in the development part, I would first look at Inside Dynamics AX 2009 (http://www.amazon.com/Inside-Microsoft-Dynamics%C2%AE-AX-2009/dp/0735626456)
If you are interested in the application part, I would start with "Introduction to Materials Management by APICS" (http://www.amazon.com/Introduction-Materials-Management-J-R-Arnold/dp/0132337614), continued by the specific application module functional training (http://www.microsoft.com/learning/en/us/course.aspx?ID=80024A&Locale=en-us)
I'm a beginner also.
ReplyDeleteActually I don't know when I used the specify classes, object, module functions, even whether its existing or not! How?
Well, if I understood your question at all, you were asking about a way to determine which class/functino to use when? Right?
ReplyDeleteIf that's the case, I am sorry to say there is no easy answer here. This you learn with experience and real-life projects and scenarios that you work with.
Some information for very common scenarios is available in the Development training, part IV.
Hi Vanya,
ReplyDeleteFirst, great post. Question: If I don't need SysFormEnumComboBox class to extend RunBase, can I still use the newParameters method on the form level to limit the selection of a combo box (instead of creating another enum of course) without modifying the class?
I am looking to implement this functionality on one of my forms.
Great work.
Regards.
Well, I don't remember the specifics of the implementation, but I think that yes, you should be able to use newParameters method without any issues.
ReplyDeleteIt's very easy to try, I think that would be the best way to go for you.
Hi!
ReplyDeleteI'm trying to implement this solution, but has a problem, the comboBox is attached to a field in a DataSource, so it doesn't work, it works if the comboBox doesn´t use any DataSource. Exists some way to implement this when the ComboBox uses a DataSource? Thanks
Well, I don't know of a way to implement that for a data source field, because the kernel tightly binds the elements to the possible field values.
ReplyDeleteHai Kashperuk-
ReplyDeleteHow are you going to implement this on Form, as we dont have control id before the super() call in the init method of the Form. I cannot find the control enum on the Form and it is throwing compile error. Do you know any other way. this only works for the run base
Not of the top of my head, sorry.
ReplyDeleteBut are you sure it throws an error when you try to access that specific FormBuildStringControl? This should exist before super(). And that's what you need, as far as I remember from the implementation of this class
Just to clarify - you are probably accessing the FormStringControl instead of its "Build" version
ReplyDelete