Business Logic on Forms
Monday, February 4th, 2008The only way a CRM system can work properly is when the inserted data can be retrieved and used in a sensible way.
The other way around, don’t put any data into the system you do not want to retrieve in a later stage. That is a complete waste of time.
Furthermore make it as easy as possible to record the data. It is not the goal to put data in the system, the goal is to have (useful and up-to-date) data in the system.In this discussion I want to show one example of a very simple way to ensure your data is valid and searchable.For example company ABC want to keep track of their customers. They want to know what kind of computer equipment they have. company ABC sells monitors, keyboards and mouses. Their are three different monitors 17″, 19″ and 21″. They have wired and wireless keyboards. and for mouses the same.
Their customers can have multiple of each. You want to record everything about your customer and you want to search the system as many as possible ways.The easiest way to record this is with a checkbox per product-category, a checkbox per sub-category and an integer per sub-category to record the amount for that sub-category.
Now if you want to search on customer who have monitor you will search on the True value of the Monitor checkbox. If one of your employees has entered 25 17″ monitors at a customer, but did not check the Monitor checkbox, this result will not show up in your query.
You can create a query that contains looks for the True value of the Monitor checkbox OR for the True value of the sub-category 17″ checkbox OR for the True value of the sub-category 19″ checkbox OR for the True value of the sub-category 21″ checkbox OR if the 17″ amount field contains data OR if the 19″ amount field contains data OR if the 21″ amount field contains data. This will not make live easier!
Another way to achieve your objectives is to add an onChange event to all the fields.
When an amount is entered you can be sure that the sub-category checkbox needs to be checked AND that the category checkbox needs to be checked. When the sub-category is checked the category needs to be checked. You can do this via a very simple onChange event.
Additional to this you can uncheck the sub-categories AND clear the amounts if an employee uncheckes the category. Because if a customer does not have monitors, than he will not have 17″, 19″ NOR 21″ monitors.
The same goes for the sub-category. If the sub-category is unchecked than the amount should be cleared. If you don’t have any 17″ monitors, than the amount is ‘null’.
code for onChange Category Level:
if (crmForm.all.new_categorymonitor.DataValue == "1")
{
}
else
{
crmForm.all.new_sub-category17.DataValue = false;
crmForm.all.new_amount17.DataValue = null;
crmForm.all.new_sub-category19.DataValue = false;
crmForm.all.new_amount19.DataValue = null;
crmForm.all.new_sub-category21.DataValue = false;
crmForm.all.new_amount21.DataValue = null;
}
code for onChange Sub-Category Level:
if (crmForm.all.new_sub-category17.DataValue == "1")
{
crmForm.all.new_categorymonitor.DataValue = true;
}
else
{
crmForm.all.new_amount17.DataValue = null;
}
code for onChange amount Level:
if (crmForm.all.new_amount17.DataValue != null)
{
crmForm.all.new_categorymonitor.DataValue = true;
crmForm.all.new_sub-category17.DataValue = true;
}





