This article is a two-part series that will first cover how to create custom entities in Microsoft Dynamics CRM to track expenses. In articles following you will learn how to create workflows for approval notification and automation.
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Create Custom Entity in CRM to Track Expenses! Okay, well maybe two custom entities…
1. Create Custom Entity in CRM to Track Expenses! Okay,
well maybe two custom entities…
www.dynamic-crm.com
2. Surprisingly enough, Microsoft Dynamics CRM does not
contain any out-of-the-box feature for expense reporting.
This is surprising because typically capturing expenses
goes hand in hand with the sales process. However, this
absence is understandable considering the intricacies
associated and more so the variance of the nuances
between the ways that companies track and reimburse
expenses.
Taking this into consideration, the architecture of
Dynamics CRM is ideal for creating a robust expense
capture, reimbursement, and tracking system.
www.dynamic-crm.com
3. We will walk you through how to create a fully functional, robust, and
scalable expense tracking, reimbursement, and reporting solution.
Better still, we will take a “coding optional” approach by creating a
custom entity for an expense header and another custom entity for
expense detail.
To kick things off, we will lay out some basic requirements. Our end
users will need a way to enter in the detail of any compensatory
expenses. Assistants may need to enter expenses on behalf of
designated users. Completed expenses are routed for approval
based on territory. Finally we will need the ability to report on
approved expenses versus actual sales for our customers.
www.dynamic-crm.com
4. The first thing we will want to do is create a new custom
entity that will act as our expense header. Please note
that when we use the term header, we are really talking
about general, common, andor summarized information
related to a series of expenditures.
To do this we will need to navigate to Settings ->
Customizations and then click on the Customize the
System option. Highlight Entities then click on the “New”
icon at the top left corner of the results pane.
www.dynamic-crm.com
5. On the new entity dialog we will enter the display name
as Expense. Before we save our new custom entity,
there are a couple of things we want to ensure. First is
that we want to verify that we have selected the
checkbox next to Notes (or Document management if
you are integrated with SharePoint). This will allow the
end user to attach receipts if necessary.
It is also a good idea to check the Activities box so we
can easily track correspondence between the end user
and the expense approver. Optionally, we can also
leverage queues to help us manage our pending
approvals, rejections, and un-submitted expenses. We
can now click on the “Save” icon at the top left of the
entity so we can start adding some fields.
www.dynamic-crm.com
7. After we save, the Fields link in the left navigation should become enabled.
We can highlight the link to display the results pane and click on the “New”
icon at the top left of the results to launch the new field dialog for each of the
following fields:
“Expense Number” – This will act as a unique reference to the set of
expenses. For our purposes this will be an auto number field, you can
choose to code something here or rather than re-invent the wheel you could
use a free plugin such as the CRM 2011 Autonumbering Solution available
on CodePlex.
“Total Expenses” – This will be a Currency field that will aggregate all of the
raw amounts entered by the end user.
“Total Reimbursed” – This will be a Currency field that will hold sum of
expenses that can be refunded. For example, your company may only pay a
percentage of certain expense types of have a cap on others.
www.dynamic-crm.com
8. www.dynamic-crm.com
“Date From” and “Date To” – These will be two separate Date Only fields that
will represent the period of time the related expenses pertain to. Now there
are a couple of options we have with these fields to improve user experience,
and if you want to use some Jscript, you could always do something like this:
This will simply set the date from field to the first of the current month and the date
to field to the last day of the current month.
9. The final field we will add to the custom entity is going to
be a reference to the user in which these expenses are
related. In certain scenarios, the built-in Created By field
may be fine. But for our requirements, the concept is that
certain users may delegate expense entry to their
assistants. To further ease the user experience, we
could leverage filtered lookups against teams or
territories but for the purpose of this article we will keep it
as a manual lookup field.
To achieve this we will add a new (Many-to-One) N:1
Relationship to the User entity. We have provided a
display name of “Employee” and we set the Display
Option to “Do Not Display”. We do this because for our
purposes, we do not want to clutter up the user form with
listings of expenses. Our viewpoint is by minimizing the
number of places where people can access data, you
can simplify the overall system and provide a clear
approach twards the users responsibilities.
www.dynamic-crm.com
11. Once we save and close the Expense entity we
can move onto a new entity that will handle the
details of the individual expenses.
On the new Entity dialog we will give the entity a
display name of Expense Item. For our purposes,
we do not need to have activities and notes
available. However, there could be a need for your
organization to leverage attachments, notes, and
activities related to the individual expenses.
www.dynamic-crm.com
12. www.dynamic-crm.com
We can now save the entity so we can jump right
into our relationships and fields. We will start with
the obvious relationship which is to the Expense
(header) entity. Again, this will be a many-to-one
relationship.
Here we will want to ensure that we do have the
Display Option for the primary entity set. In our
case we will leave it as the default of “Use Plural
Name”. This will allow us to see all of the related
expense items directly on the expense header.
14. Next we will create another many-to-one relationship.
This time we will want to relate an Account to the
Expense item. In doing so, we can gain some extremely
valuable metrics (adding valuable metrics adds value to
what we bring as a technical resource).
What we want to attain is the ability to report on how
much money we spend with an account compared to
how much business we get. This can be further analyzed
to the sales person where we report how much a sales
person spends on an account in comparison to how
much business we win.
www.dynamic-crm.com
16. It is always worth mentioning that you will want to
understand your business needs in order to create the
appropriate relationships here. Additionally, anytime you
create a relationship you should fully leverage the power
of mappings.
In our example it makes sense to map the Employee
field to the Expense item which will provide additional
analytics. For more on this you can read Customizing
Microsoft CRM to get the Ultimate User Experience (UX)
www.dynamic-crm.com
17. Next we will want to add some fields to the
Expense item.
“Expense Description” – This will be a field of
type “Multiple Lines of Text” to allow the end
user to comment on the expense.
“Expense Date” – This will be a Date Only field to
identify when the expense took place.
www.dynamic-crm.com
18. The next three fields will be used in conjunction with each other.
◦ “Refundable Amount” – This will be a read only Currency field to
calculate the actual reimbursed amount.
◦ “Expense Type” – This will be an Option Set that will hold the
various expense types of expenses that an end user can enter.
◦ “Expense Amount” – This will be a Decimal Number field for the
amount of the expense item. For our purposes, we used a
decimal number because this field may not always represent a
monetary value as you will soon see.
www.dynamic-crm.com
19. The Expense Types will act as the driver for how we need to handle
the amount entered by the user. For example, the company may
only allow up to $100 a day for Meals. If the user enters anything
over 100 into the expense amount field, the refundable expense
should only calculate $100. field).
Now if the user selects Mileage as the expense type, they are going
to enter in the miles driven into the expense amount field (Ah ha,
this is why we did not make it a currency field).
www.dynamic-crm.com
20. www.dynamic-crm.com
We can then calculate the amount entered times 56.5
cents (which is the 2013 standard mileage rate) to
calculate the refundable expense. We will discuss how
these get populated more in part 2 of this article.
The final thing we want to accomplish, in regards to the
entities, is setting up the forms in a logical and usable
layout.
Keep in mind that the expense item, in this example
would be an ideal place to leverage a “Copy From”
feature similar to the one we wrote about in the article
Get Code Snippets to Clone a Record in CRM!
22. www.dynamic-crm.com
In part 2 we will show you how to create workflows to populate form values
and handle the routing of Expenses for approval. Until then, it is important
to point out the implications that security will have in this process.
Additionally, when it comes to our relationship of Expense to Expense
items you will need to pay close attention to how granting Append and
Append to affects the behavior of the relationship. For more information,
refer to Richard Knudson’s blog on Dynamics CRM 2011 Security Roles.
Be sure to read part 2 of our series to learn about how to create crm
workflows for approval notification and automation. Additionally, learn how
to customize crm with Script Author which can take you that extra step by
automating the process by which you can automatically assign the current
user to a look-up field on a form in MS CRM 2011.
Happy coding.
23. What do you get out of this?
◦ The Dynamic-CRM community provides access to available
product downloads and to our sample code archives at no charge.
◦ Registration is also free!
◦ Register at http://dynamic-crm.com/registration/
View this blog article at http://dynamic-crm.com/create-
custom-entity/ and find part 2 and 3 in the series here as
well!
www.dynamic-crm.com
24. Would you like to customize MS Dynamics CRM
2011 forms without having to read, write, or debug
code?
Oh, and in about half the time it normally takes?
Then…… Download “Script Author” for FREE!
www.dynamic-crm.com
25. Script Author is Dynamic-CRM’s javascript
generator that generates scripts in formatted,
readable code for MS Dynamics CRM 2011.
Script Author works with existing customizations,
there is no intricate syntax to memorize and it
requires NO programming knowledge!
www.dynamic-crm.com
26. Download your FREE version of Script Author.
When you are ready to push your customizations
to your CRM environment, then purchase your
license key(s)!
Happy coding!
www.dynamic-crm.com