Change the default purpose role of a (vendor) contact (with Delegate)

1) When we add a new contact in the vendor card’s contact information (see steps 1,2,3), we see that by default system select role “Business”. In this example, I show you how we can change this role to “Home”, with help of delegate in standard code.

2)

3)

4) When we put the debugger in the method “electronicAddressPostWrite” of the class DirPartyFormHandler_Entity, we can see how system assigned default role.

5) Via method “getDefaultLocationRole” in the “If” clause, we can see the reference to the class “LogisticsLocationEntity” ,method “getDefaultLocationRoleFromEntity”

6) When we open the method we see the code which assigned default purpose “business”.

7) In the the next line of this method we see the reference to a delegate (LogisticsLocationEntity::getDelegateCaller() ) which gives us the opportunity to change standard behavior.

If we open the class LogisticsLocationEntity we can see the method “getDelegateCaller”, which is calling an instantiation of the LogisticsLocationEntity class.

In the second argument of the code in line 709 the call to the delegate is made:

In fact this logic we see at line 709 of the “GettingDefaultLocationRoleFromEntity” (see screenshot point 7)) is calling subscriber class/method, which is actually contains execution logic. Delegate itself does not contain this code, it only refers to. I will explain at point 9 how we can find subscriber and extend it.

8) We see that our delegate (gettingDefaultLocationRoleFromEntity) need tableId as parameter ( _entityTableId) which we can see is in our example TableId 3135. To find corresponding table name, open SQL table SQLDictionary and select on tableID 3135. We see that the table name is ‘VendTable’.

9. ) In point 7 we saw that class LogisticsLocationEntity, hold delegate “GetDefaultLocationRoleFromEntity”. Now we need to search for it’s subscriber. In order to make changes we have to extend the subscriber. In screenshot below we see the delegate at line 690.

to find the subscriber, right click the delegate name we see at line 690 (“gettingDefaultLocationRoleFromEntity”) and do a right mouse click. In the dialog select option “Find All References (Shift – F12)”. In the Find Symbol Results dialog we can find the subscriber. In our example: classes/LogisticsLocationEntityAppUtil/onGettingDefautLocationRoleFromEntity is the subscriber.

12) As we cannot make changes directly in the subscriber (see screenshot) we need to copy relevant code from it and create a new class, and paste it and make our changes there.

13) In below screenshot you can see example code to change default purpose role to “Home”. In this example the class is placed in the “Fleet Management” model. If you use “Fleet Management” (or your own) model, be aware that in the “Selected referenced packages” (Dynamics 365 | Model Management | Update Model parameters) package “Application Suite” should be ticket.

Selected referenced packages

14) If we going to test solution we see that default role for each new created contact is now “Home”: