Quantcast
Channel: Dynamics 365 Blog
Viewing all articles
Browse latest Browse all 1498

Mask characters

$
0
0

Yesterday, I had a support request where customer wanted to set a fixed length for the main accounts and they did not want to specify a type of characters – 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:

publicstaticboolean 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)
    {
        returntrue;
    }
 
    // Value must be same length as the mask
    strLength = strlen(_value);
    if (strLength != strlen(_mask))
    {
        returnfalse;
    }
 
    // 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))
                {
                    returnfalse;
                }
                break;
 
            case #SymbolLetters:
                if ((valueChar < #FirstLetter) || (valueChar > #LastLetter))
                {
                    returnfalse;
                }
                break;
 
            case #AnySymbol:                              
                break;                                    
 
            default:
                if (valueChar != maskChar)
                {
                    returnfalse;
                }
                break;
        }
    }
 
    returntrue;
}

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.

 

Have a good day,

Roman


Viewing all articles
Browse latest Browse all 1498

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>