Tuesday, July 26, 2011

Enum elements customizations

The scenario is to add two new elements in a standard enum and change the labels of existing enum elements to new label, but in one form, all this customized elements (standard with Label changed + new) must be shown whereas in other form, the standard enum elements only need to be shown.
The enum is CustVendorBlocked which is used by customer form and vendor form in general tab under Administration group. The standard elements are .

I duplicated this standard enum, say, DUP_CustVendorBlocked. Next, I have added two new elements in the standard enum and changed the labels of existing elements. Now standard enum contains five elements as follows

CustVendorBlocked::No (Label:Active)
::Invoice (Same as standard)
::All (Label:In active)
::Onhold (Label:On-hold) – New elements
::Dispute (Label:Dispute) – New elements

So the customer master form shows all these elements with new Label but the vendor master should show only standard elements with standard labels i.e.

CustVendorBlocked::No
::Invoice
::All

If the requirements were not to change the existing Label and only addition of new elements, then we could have used the following method in the vendor form. By doing so, the cutomer from will display all existing & new enum elements but the vendor from will only display the standard enum elements. As the new elements have a higher enum values, so on delete, it will not disturb the enum values of the existing elements.

in combox:enter:
public void enter()
{
super();
this.delete(enum2str(CustVendorBlocked:: Onhold));
this.delete(enum2str(CustVendorBlocked:: Dispute));

}

Because, these are the new elements and keeping up-gradation in mind, assigna enum values as 100, 101. Hence, during delete, it will not disturb the existing enum values.

But apart from this, we also need to keep the existing enum labels as per standard in the vendor form, which I have not found any X++ code to change the enum elements labels dynamically. So what I did, I have used edit method on the vendor form instead of bounded enum field, and used unbounded enum field control, I used the duplicated standard enum as specified above. Hence, I am able to get the standard set of enum elements and on selection of an enum, I have set the standard vendor enum field based on this selection.

No comments:

Post a Comment