Customizing a text field to accept only alphanumeric value.

Hi,

I have a requirement to accept only alphanumeric values for a field in a from in D365 F&O. However I am unable to do it. Can anyone please help me achieve this. Also where should I be performing the change ie edt/table/form?

Probably the best place would be validateField() method on table.

Yes thanks I have used that it’s working fine!

Just one more query I am getting a BP error that the code is unreachable when I am using it for 2 fields. My code is:

public boolean validateFieldValue(FieldName _fieldName, int _arrayIndex = 1)
{
boolean ret;

ret = super(_fieldName, _arrayIndex);
// FieldId fieldId = args.getArg("_fieldId");
switch(_fieldName)
{
case fieldStr(ArdoBrand, BrandName):
str s1 = strAlpha(this.BrandName);

if (strlen(s1) != strlen(this.BrandName))
{
ret = ret && checkFailed(“Field should be alphanumberic!”);
}
return ret;
break;
case fieldStr(ArdoBrand, BrandDescription):
str s2 = strAlpha(this.BrandDescription);

if (strlen(s2) != strlen(this.BrandDescription))
{
ret = ret && checkFailed(“Field should be alphanumberic!”);
}
return ret;
break;
}

return ret; means that you leave the method; you’ll never get to break. The break statement will never get called.

You should decide whether you want to set ret variable and continue or return from the method. Setting the variable and never use it doesn’t make a good sense.

Option 1:

if (strlen(s2) != strlen(this.BrandDescription))
{
	ret = checkFailed("Field should be alphanumberic!");
}
break;

Option 2:

if (strlen(s2) != strlen(this.BrandDescription))
{
	return checkFailed("Field should be alphanumberic!");
}
break;

Also, you code ret && checkFailed(“Field should be alphanumberic!”) would mean that if super() return false, you wouldn’t add your message to infolog. I think it’s not what you wanted. And if you don’t want to check your condition if super() return false, skip the whole check and not just the message.

Okay. Got it. Thanks for your help.