RM is a pretty complete module that is not often highly customized or verticalised. However, we will describe some possible changes and how to integrate an add-on, in our case the Squash application, with Relationship Management.
All examples in this article are part of the objects downloaded for the article, Microsoft Dynamics NAV 2009: Apply reverse engineering to customize our application.
Salutation formula types
By default, the system has two salutation formula types— formal and informal, allowing us to print Dear Mrs. Brown, or Dear Angela. But, what if we want to print Attn. Mrs. Brown?
For this, we need to first add an option to the Salutation Type field in the Salutation Formula table.
Add the option
Support the formula
Next, we want to use the formula when printing a Contact Cover Sheet. This uses the Format Address functionality from Codeunit 365.
This Codeunit is the single point in Dynamics NAV where all the address formatting is done.
The formatting of contact persons is done in the function ContactAddrAlt. We should make the following change.
WITH ContAltAddr DO BEGIN
AddrArray,”Company Name”,”Company Name 2″,
City,”Post Code”,County,”Country/Region Code”);
(Cont.”Company No.” ”):
WITH Cont DO
// AddrArray,ContCompany.Name,ContCompany.”Name 2″,
// Name,Address,”Address 2″,
GetSalutation(5, Cont.”Language Code”),Address,
“Address 2″,City,”Post Code”,County,
Always comment out the original line of code before you make a change. This will enable you to always go back to standard code and help when upgrading this solution to a newer version. Most NAV partners and developers have their own way of documenting and commenting. The example in here is the Minimum comment requirement.
The GetSalutation function
In our modification, we use the GetSalutation function in the Contact table (5050) instead of the Name field. Let’s have a look at that function and analyze what it does.
IF NOT SalutationFormula.GET(“Salutation Code”,LanguageCode,
CASE SalutationFormula.”Name 1″ OF
SalutationFormula.”Name 1″::”Job Title”:
NamePart := “Job Title”;
SalutationFormula.”Name 1″::”First Name”:
NamePart := “First Name”;
SalutationFormula.”Name 1″::”Middle Name”:
NamePart := “Middle Name”;
NamePart := Surname;
NamePart := Initials;
SalutationFormula.”Name 1″::”Company Name”:
NamePart := “Company Name”;
CASE SalutationFormula.”Name 2″ OF
FOR i := 1 TO 5 DO
IF NamePart[i] = ” THEN BEGIN
SubStr := ‘%’ + FORMAT(i) + ‘ ‘;
IF STRPOS(SalutationFormula.Salutation,SubStr) > 0 THEN
The function uses two parameters: SalutationType and LanguageCode. With these values and the salutation code of the contact, it checks if there is a valid formula. Since we only added a new option, the code still works because at database level, the Option field is translated to an Integer.
For documentation purposes, we could also implement the new option value in this function. The downside of that would be that we do a modification that is not technically necessary, but needs to be maintained and upgraded.
Depending on the order of the formula, the necessary name fields are combined and used as the return value of the function.
Set up the salutation formula
If we want to use our new Salutation formula, we need to set it up first. We will do this for F-MAR to test it with CT100191 Megan Sherman from American Wood Exports.
Test the solution
After adding the new formula, we print a cover sheet from the Contact Card using the Contact Cover Sheet option from the Report actions. The result will look like this:
Customer and vendor numbering
Another common requirement from end users is to maintain the same number when creating a customer or vendor from a contact.
This can be done by adding one line of code to the CreateCustomer function in the Contact table.
//* Maintain Contact No. >>>
Cust.”No.” := “No.”;
//* Maintain Contact No. Cust.INSERT(TRUE);
This works, because by populating the No. field the number series functionality in the OnInsert trigger does not start.
IF “No.” = ” THEN BEGIN
xRec.”No. Series”,0D,”No.”,”No. Series”);
Disabling direct creation of customers and vendors
When using this option, it should be disabled to directly create a customer or vendor. This can be done easily by removing the No. series from the Sales & Receivables setup and Purchases & Payables setup. This results in a runtime error message when creating the customer or vendor.