luni, 9 mai 2016

Check if string enum element is part of real enum.

When importing lines from a .csv file, at some point, i have to check if the account type is correctly provided.

Here is the method for this and a call example :

//Example: enumElementIsValid("Vendor", "LedgerJournalACType");
private boolean enumElementIsValid(str _inputEnumElement, str _inputEnumType)
{
    boolean isValid = false;

    DictEnum enum = new DictEnum(enumName2Id(_inputEnumType));

    int i;
    for (i = 0; i < enum.values(); i++)
    {
        //check if input account equals one of the labels.
        if (_inputEnumElement == SysLabel::labelId2String2(enum.index2LabelId(i), 'en-za') ||
                _inputEnumElement == SysLabel::labelId2String2(enum.index2LabelId(i), 'en-us'))
        {
            isValid = true;
        }
    }
    return isValid;
}


So, i am sending the enum name for this task, and its element as it was read from the .csv file.

I've chosen to compare the string value from the file with the label of the enum element because that's what the users see and not the actual name. And I've done this in two languages.

Niciun comentariu:

Trimiteți un comentariu