Mask characters

Yesterday, I had a support request where the customer wanted to set a fixed number of characters for the main accounts and they did not want to specify the type of characters used – they wanted to have a possibility to enter both numeric and alphabetic characters.

In the form Chart of accounts, you can specify your accounts format in the field Main account mask.

There you can use the following mask characters:

& – allow any alphabetic character

# – allows any numeric character

The problem was that there’s no literal mask character that allows alphanumeric or any characters.

For that purpose, we modified the table FinancialTagCategory method doesValueMatchMask adding the new mask character:

? – allow any symbol

Here’re the modifications:


public static boolean doesValueMatchMask(DimensionValue _value, DimensionValueMask _mask)
{
    #DEFINE.SymbolNumerals(‘#’)
    #DEFINE.SymbolLetters(‘&’)
    #DEFINE.AnySymbol(‘?’)                              
    #DEFINE.FirstNumeral(‘0’)
    #DEFINE.LastNumeral(‘9’)
    #DEFINE.FirstLetter(‘A’)
    #DEFINE.LastLetter(‘Z’)
 
    int strLength;
    int i;
    char maskChar;
    char valueChar;
 
    // No mask allows any value
    if (!_mask)
    {
        return true;
    }
 
    // Value must be same length as the mask
    strLength = strlen(_value);
    if (strLength != strlen(_mask))
    {
        return false;
    }
 
    // Ensure each character matches the literal mask character or is appropriate for the wildcard (number/letter) specified
    for (i = 1; i <= strLength; i++)
    {
        maskChar = substr(_mask, i, 1);
        valueChar = substr(_value, i, 1);
 
        switch(maskChar)
        {
            case #SymbolNumerals:
                if ((valueChar < #FirstNumeral) || (valueChar > #LastNumeral))
                {
                    return false;
                }
                break;
 
            case #SymbolLetters:
                if ((valueChar < #FirstLetter) || (valueChar > #LastLetter))
                {
                    return false;
                }
                break;
 
            case #AnySymbol:                              
                break;                                    
 
            default:
                if (valueChar != maskChar)
                {
                    return false;
                }
                break;
        }
    }
 
    return true;
}

Disclaimer: This programming example is for illustration purposes only. Microsoft disclaims all warranties and conditions with regard to use of the programming example for other purposes. Microsoft shall not, at any time, be liable for any special, direct, indirect or consequential damages, whether in an action of contract, negligence or other action arising out of or in connection with the use or performance of the programming example. Nothing herein should be construed as constituting any kind of warranty.


This allowed us to enter any values and still control the length of the accounts.

 I hope it helps some of you and highlights the general literal mask characters that, by the way, used across the product – for example, in the project module – the Subproject ID format field.

The field Subproject ID format is used as a format when system generates new subproject ID. This is not a mask field, but you can use the same characters there – # and &.

 

Have a good day,

Roman