Introduction:
The SAP Business One Add-on Electronic File Manager Format Definition (EFM) can import the structure (Target) for the Electronic Format for electronic documents type xml from one schema file (xsd), or from an existing xml file.
In this blog I want to share with you a handy use of the SAP Business One add-on EFM to include additional user defined validations on a pre-existing electronic format, type XML that has already embedded validations coming from its schema xsd.

EFM import target
You cannot edit or delete the validations that come from the schema using the EFM add-on, which makes sense to keep the validations that had an external origin. For that you need to create a new schema xsd and import it again.
But what If the validations imported are too generic for my needs?
Can I add additional Validations?
You can create additional validations with the EFM add-on.
The additional validations can be edited or removed in the add-on, saving you the time an effort of creating a new schema xsd.
In this example:
The original schema (xsd) file has brought to my electronic format the
Target element
CustomerName: with a definition
type= xs:string.

xsd validation
Using EFM I have done a direct mapping, linking the
Target node
CustomerName to the
Source field
CardName, which is the
Business Partner Name shown in the Invoice.

CustomerName->CardName (direct mapping).
If I wanted to have an additional validation to accept up to 50 characters when processing the xml I can add and additional validation using the Add-on EFM, I don’t need to change or create the xsd file and import it again, by
following these steps:
STEPS:
1- In the
Validation tab of the target field
Mapping Settings where I want my validation, I press the ‘add’ button to unfold the type of validation desired. In my example I will use ‘Length’.

Validation: Add. Select: Length.
2-Then I enter the parameters for my validation.

Validation parameters
In my example I aim to avoid more than 50 characters in the string or leaving it empty.
I enter my
Length Range From 1
To 50.
I mark as ‘Error’, to stop the xml file being generated. You can set it as a 'Warning', but that will defeat the purpose.
Finally, I define the message that I want to see in
SAP Business One as an
Error System Messages when the validation fails.
See the syntax in the example:
format('"CustomerName" - Value "{0}" exceeds 50 characters', .)
Syntax:
format
( [open parenthesis]
‘ [single quotation mark]
“ [Double quotation mark] + your free text+ [Double quotation mark]
value "{0}" the variable content inserted in the text of your message.
more free text to be shown after the variable.
‘ [single quotation mark] the end of your text
, [comma]
. [dot] stands the content for the variable value "{0}", to be captured in the node
)[close parenthesis] to finish your message.
NOTE:
You can create more sophisticated validations using a
Customize validation using expressions and functions (see more in the EFM Help File to find functions).
Your expression should be set in a positive or
true manner, meaning that you need to define the pattern that meets the validation as true for the error or warning to happen when the pattern is not met/false.
The same example as above, avoiding longer that 50 could be set with this expression:
Expression Function string-length(.) Less than or equal Constant Value 50

Customized