Overview
Finnish Business ID ("Y-Tunnus" in Finnish) is a is a code given to businesses, organizations, and associations by the PRH or the Finnish Tax Administration. It consists of seven digits, a dash, and a control mark, for example 1234567-8.Here is a simple validation script to check that the entered business ID to a text property matches these requirements. This chapter in M-Files User Guide explains how to use validation scripts: https://www.m-files.com/user-guide/latest/eng/Validation.html.
Note that this validation script does not check the validity of European VAT identification number, which adds FI to the beginning of ID and omits the dash.
Solution
Please notice that scripting is not part of standard support, and this is just an example script to show howto use API. Be aware that all scripts are run at your own risk.
----
' Type: Validation
' Property: Y-tunnus (Business ID)
' Name: Validate the Finnish Business ID Number (Y-Tunnus)
' Description: Simple validation script for the Finnish Business ID "Y-tunnus".
Option Explicit
' Get the assigned value as unlocalized text.
Dim szValue : szValue = PropertyValue.GetValueAsUnlocalizedText()
' Check the length and raise an error if it is different than 9.
If Len( szValue ) <> 9 Then
Err.Raise MFScriptCancel, " The value length must be exactly 9 characters "
End if
' Convert the value to a VBScript array by splitting the string value at the '-' character.
Dim aValue : aValue = Split( szValue, "-", -1, 1 )
' Check the number of elements in the created array.
If UBound( aValue ) <> 1 Then
' Raise an error if there are more or less than two elements (starts with 0, so compare the upper bound to 1).
Err.Raise MFScriptCancel, "Business ID must be in format NNNNNNN-N"
End If
' Check the length of the both parts of the business ID.
If Len( aValue( 0 ) ) <> 7 OR Len( aValue( 1 ) ) <> 1 Then
' Raise an error if first part has the length different than 7
' or the length of the second part is different than 1.
Err.Raise MFScriptCancel, "Business ID must be in format NNNNNNN-N "
End If
' Check if the second part contains only a number character.
If Not IsNumeric( aValue( 1 ) ) Then
' Raise an error if the first part contains different characters than a number.
Err.Raise MFScriptCancel, "Business ID can only include numbers and '-' character"
End If
' Validate the checksum.
' Get the first part of the business ID.
Dim iID : iID = aValue( 0 )
' Define a variable for the checksum.
Dim iChecksum : iChecksum = 0
' Define an array of values to which the values from the first part of the ID should by multiplied.
Dim aMultiply : aMultiply = Array( 7, 9, 10, 5, 8, 4, 2 )
' Define a variable for the reminder.
Dim iReminder : iReminder = 0
' Loop through each character of the first part of the business ID.
' Check if each character is a number and sum up the checksum.
Dim i
For i = 1 To Len(iID)
' Check if the character is a number.
If Not IsNumeric( Mid( iID, i, 1 ) ) Then
Err.Raise MFScriptCancel, "Business ID can only include numbers and '-' character"
End If
' Sum up the checksum.
iChecksum = iChecksum + Mid( iID, i, 1 ) * aMultiply( i - 1 )
Next
' Validate the checksum.
' Check if the integer reminder after dividing the checksum by 11 is greater than 0,
' and set the appropriate value to the reminder variable.
If iChecksum Mod 11 > 0 Then
iReminder = 11 - (iChecksum Mod 11)
Else
iReminder = 0
End If
' Check if the reminder is different than the second part of the business ID.
If CStr( iReminder ) <> aValue( 1 ) Then
' Raise an error if it is different.
Err.Raise MFScriptCancel, " Business ID control mark does not match"
End If
----
Sample translations to Finnish on error prompts:
The value length must be exactly 9 characters
Syöttämäsi arvon pituus pitää olla 9 merkkiä pitkä
Business ID must be in format NNNNNNN-N
Y-Tunnus kuuluu olla muodossa NNNNNNN-T
Business ID can only include numbers and '-' character
Y-Tunnus voi sisältää vain numeroita ja '-' merkin
Business ID control mark does not match
Y-Tunnuksen tarkistusnumero ei täsmää
