Wednesday, January 16, 2013

Making sure that the data is entered in the right form

As all admins know, sometimes users would like to input data in a different form than it actually should be. I'm not going to go in to all the problems incorrectly formatted data can cause but sometimes external systems require some key data in the right format and there just can't be any errors in the way it is typed in.

We have integrated Intrum Justitias credit decision and monitoring services straight in to Salesforce so that all the salespeople can just click a button to request a credit decision for a customer and get the decision in a matter of seconds. It is a part of our sales process and a required step before making an offer. Actually we get a lot more than just the credit decision. They provide us with address information and the official name of the company. It is great for our data accuracy because we can also update that information to the account with a single click. So by doing things by the process it actually saves salespeople time! How wonderful is that?

The service works great, but it is solely based on the business code that we use in Finland (locally known as "Y-tunnus"). All the registered organizations and corporations have it and it has a standard form: 1234567-8. And in order for the service works we need to make sure that we input the business code properly.

So all the business codes in Finland are nine characters long and they are formed of 7 digits between 0-9 in the beginning, a dash in the middle and 1 digit between 0-9 in the end. It's important to take the business code apart like this because we will need write a validation rule and express the form of our business code in a REGEX function.

Creating the validation rule

So we have a field called "Y-tunnus" and we want to make sure that the data entered in to this field has 7 numbers, a dash and one number after the dash. First we need to go to the Account object and create a new validation rule. The validation rule should give us an error message if the field "Y-tunnus" is not following the aforementioned form factor. So
NOT (REGEX( Y_tunnus__c , "[0-9]{7}-[0-9]{1}"))
The way the function works is widely documented on Salesforce's support site but basically in this case we first define that we need numbers between 0-9 with the [0-9] and that we need 7 of them {7}. After that we just use the normal dash and define that it should be followed with a number between [0-9] and that there should only be one of those {1}. And because the validation rules always work a b it backwards in logic, we need to add the NOT () funcion. So when the "Y-tunnus" is NOT following the defined form it gives you an error message.

If you only want this validation rule to be active when there is some information in the field you can add
&& NOT(ISBLANK(Y_tunnus__c))
to the validation rule. That way it will only give you an error if there is something in the field but it doesn't match the criteria.

Since we also have business in Sweden and we need to keep track of their företagsnummer I'll chuck in a prepared formula for their 123456-7890 style business codes as well for good measure. :)
NOT (REGEX( Foretagsnummer__c , "[0-9]{6}-[0-9]{4}"))
I hope this will help you keep your business numbers in check.

1 comment:

  1. Hi,

    This looks very good!. I've been thinking also in the possibility of implementing a formula to calculate the reference number for invoices (the check number, like this from Nordea. At the moment I implemented it in code, but I believe it can be done using math functions in a formula.

    ReplyDelete