Categories: Tutorials

Microsoft Dynamics NAV: Customizing Relationship Management

4 min read

 

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.

ContactAddrAlt()

ContIdenticalAddress:
WITH ContAltAddr DO BEGIN
GET(Cont.”Company No.”,CompanyAltAddressCode);
FormatAddr(
AddrArray,”Company Name”,”Company Name 2″,
Cont.Name,Address,”Address 2″,
City,”Post Code”,County,”Country/Region Code”);
END;
(Cont.Type=Cont.Type::Person) AND
(Cont.”Company No.” <> ”):
WITH Cont DO
FormatAddr(
// AddrArray,ContCompany.Name,ContCompany.”Name 2″,
// Name,Address,”Address 2″,
AddrArray,ContCompany.Name,ContCompany.”Name 2″,
GetSalutation(5, Cont.”Language Code”),Address,
“Address 2″,City,”Post Code”,County,
“Country/Region Code”)

 

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.

GetSalutation()
IF NOT SalutationFormula.GET(“Salutation Code”,LanguageCode,
SalutationType)
THEN
ERROR(Text021,LanguageCode,”No.”);
SalutationFormula.TESTFIELD(Salutation);
CASE SalutationFormula.”Name 1″ OF
SalutationFormula.”Name 1″::”Job Title”:
NamePart[1] := “Job Title”;
SalutationFormula.”Name 1″::”First Name”:
NamePart[1] := “First Name”;
SalutationFormula.”Name 1″::”Middle Name”:
NamePart[1] := “Middle Name”;
SalutationFormula.”Name 1″::Surname:
NamePart[1] := Surname;
SalutationFormula.”Name 1″::Initials:
NamePart[1] := Initials;
SalutationFormula.”Name 1″::”Company Name”:
NamePart[1] := “Company Name”;
END;
CASE SalutationFormula.”Name 2″ OF

END;

FOR i := 1 TO 5 DO
IF NamePart[i] = ” THEN BEGIN
SubStr := ‘%’ + FORMAT(i) + ‘ ‘;
IF STRPOS(SalutationFormula.Salutation,SubStr) > 0 THEN
SalutationFormula.Salutation :=
DELSTR(SalutationFormula.Salutation,STRPOS(Salutation
Formula.Salutation,SubStr),3);
END;
EXIT(STRSUBSTNO(SalutationFormula.Salutation,NamePart[1],
NamePart[2],NamePart[3],NamePart[4],NamePart[5]))

 

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.

CreateCustomer()

CLEAR(Cust);
Cust.SetInsertFromContact(TRUE);
//* Maintain Contact No. >>>
Cust.”No.” := “No.”;
//* Maintain Contact No. <<<
Cust.INSERT(TRUE);
Cust.SetInsertFromContact(FALSE);

 

This works, because by populating the No. field the number series functionality in the OnInsert trigger does not start.

OnInsert()
IF “No.” = ” THEN BEGIN
SalesSetup.GET;
SalesSetup.TESTFIELD(“Customer Nos.”);
NoSeriesMgt.InitSeries(SalesSetup.”Customer Nos.”,
xRec.”No. Series”,0D,”No.”,”No. Series”);
END;

 

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.

Packt

Share
Published by
Packt

Recent Posts

Top life hacks for prepping for your IT certification exam

I remember deciding to pursue my first IT certification, the CompTIA A+. I had signed…

3 years ago

Learn Transformers for Natural Language Processing with Denis Rothman

Key takeaways The transformer architecture has proved to be revolutionary in outperforming the classical RNN…

3 years ago

Learning Essential Linux Commands for Navigating the Shell Effectively

Once we learn how to deploy an Ubuntu server, how to manage users, and how…

3 years ago

Clean Coding in Python with Mariano Anaya

Key-takeaways:   Clean code isn’t just a nice thing to have or a luxury in software projects; it's a necessity. If we…

3 years ago

Exploring Forms in Angular – types, benefits and differences   

While developing a web application, or setting dynamic pages and meta tags we need to deal with…

3 years ago

Gain Practical Expertise with the Latest Edition of Software Architecture with C# 9 and .NET 5

Software architecture is one of the most discussed topics in the software industry today, and…

3 years ago