Hi All,
I have been working on a tool where i have a requirement that should number of if conditions and based on True/False it should be calculated premium value.
I have 5 ShipTypes and 12 types of LimitLiabilitys. I'm trying to build a tool based on some rating points which were assigned to Ship Type and LimitLiabilitys.
Ex : If ShipType= ShipType1 then Rating for ShipType1 is 1 like
ShipType= ShipType2 then Rating for ShipType2 is 2
ShipType= ShipType3 then Rating for ShipType3 is 3
ShipType= ShipType4 then Rating for ShipType4 is 4
ShipType= ShipType5 then Rating for ShipType5 is 5
and
if LimitOfLiability is 50,000,000 then Rating is 1
if LimitOfLiability is 100,000,000 then Rating is 2
...
....
if LimitOfLiability is 600000000 then Rating is 12
Final calculation will be
If ShipType =ShipType1 and LimitOfLiability=50,000,000 then Premium would be 1 (ShipType1 rating)*2 (LimitOfLiability rating)=2
I can do this calculation by using if condition and Assign. But, if i use 'If' condition i have to use more than 100 if conditions (Each ShipType and each LimitofLiability needs to be checked.).
Is there any other way where i can check with less 'If' conditions and Assign each value based on Rating?
Here i'm attaching the example 'If' condition.
Please advise?
Thanks
Ramesh.
I'm using Web Development 11
Hi,
I think that in the table that you are storing the ShipType you can add a new attribute, called rating, and in the table where you have the LimitOfLiability add a new attribute called rating too and, in the end, just get the Correct ShipType and the Correct LimitOfLiability and make your calculations with the returned rating values.
So, in resume, the ideia is for every ShipType you store its rating in the same record and for each LimitOfLiability you store its rating too.
Hope this can help.
Best regards,
Ricardo
Hi Ricardo,
Thank you for the quick response. Instead of new attribute so far i have been working with local variable to store the Rating. But it is not working.
Could you please advise?
Ramesh Pilla wrote:
Hi Ramesh,
Why don't you design different entities in database to store all above information by maintaining referential integrity. I think it is a better way, you can retrieve data easily by writing simple query.
Thanks,
Sachin Mahawar
Can you share the OML or a print of your code please?
Ricardo M Pereira
As far as i understood your problem is not the technical limitation of platform but your business use case.
Let me explain you:
1. you need to group you condition like similar fields and values which will determine the result true or false.
2. By using those groups then you can take the decision and set the final values.
3. You might have lots of permutation and combination but final decision must be result of those combinations.
First draw a sketch on paper and identify all the possible scenario and then try to group them and them build your code.
Regards,
Manish Jawla
Hi Ricardo and Manish,
Thank you for the advise.
Here i'm attaching my OML file and please go thru it.
@Manish : I have done the same permutations and combinations but if we do that we end up writing more than 100 if conditions which i don't want to do.
I have seen you code and found that you can optimize your code by grouping you concepts and create separate actions/functions for them:
like for above piece of code you can move this logic into separate action/function where input parameter is LimitofLiability and it will return value based on calculation. In similar fashion you can minimize your code at page level and later you can optimize you functions.
you need to group the concepts and create the functions for the same.
Hope this helps.
as both Ricardo and Sachin already said, your problem asks for some proper data modeling, where the applicable rates are stored in relation to the relevant parameters.
I Don't really know the exact formula, but looking at your oml, it's something like this, i guess
premiumValue = a * b * c * d * f * g with g being a dollar amount (?) and a to f being factors to augment it for some reason for example 2*3.1*1*1.25*1.2*1.3*1200000
g I guess the 1.200.000 is some sort of default premium (in $ ?) that needs to be adjusted, dependent on some parameters such as ship type. Even this single piece of information should not be hardcoded in the software, but managed in some table or site property. Or at least make it a variable being set at the top of your code instead of repeating it all over. What if your business changes and it should be 1.000.000, are you going to go over all the spots where you used and change it by hand ??
a I guess the first one of the factors is the ShipCollisionRatingFactor, so I don't know your business, but if it is as simple as this factor depends on the type of ship, then you can model this as a simple table. Since there is already a ShipType static entity, adding a CollistionFactor column to that would do.
ShipType CollisionFactorYaght_SailingVessel 1.00 CargoShip 1.75 FishingVessel ..... TowingVessel ..... PassengerShip 2.00
ShipType CollisionFactor
b I guess the second one of the factors is the LimitOfLiabilityRatingFactor, again if it is as simple as the factor being dependent on the value of LimitOfLiability, put it in a table
LimitOfLiabilitye LimitOfLiabilityFactor 50.000.000 1.00 100.000.000 1.60 150.000.000 2.00 200.000.000 2.20 250.000.000 2.40 300.000.000 2.60 350.000.000 ....................
LimitOfLiabilitye LimitOfLiabilityFactor
and so on for the other factors.
In your code, you can then simply retrieve the factors that match the current situation from the database with a query, and use them in the formula. (or alternatively, you could create a lookup table as a local variable and lookup the values there, if for some reason you don't want to use database)
Above is very simple example, if your business is more complex, then your datamodel would have to be more complex to reflect that. A factor might for example depend on multiple variables instead of one.
So to recap :
* please, please, please don't hardcode any of the values in your logic
* replace all sets of if var a = value x then var b = value y by lookup tables (be it in the database or in local memory)
* instead of repeating the same formula over and over in your logic with different values, have a local variable for each of the factors, determine each factor by looking it up in the database, and then calculate your premium with the formula once by multiplying all factors with the default premium value.
Good luck,
Dorine
Indeed, Like Dorine said. I think it's good to store the data in a database.
Furthermore I would recommend to update your code to make it better readable. Create an ServerAction to handle this code.
Thank you for your valuable suggestions. I can achieve this by introducing server action and that works fine.
Thank you so much for your support.
Hello Ramesh,
I think that I have found the solution for your problem in the QuotePage.SubmitQuote on the if's side.
This collections of if's can all be replaced with one simple instruction
Please let me explain better, what I did to test.
1 created an static entity
2 changed the ID type from number to TEXT
3 added a new attribute VALUE (type text also)
Now comes all the work
4 for each IF, I created one record with the ID value of "100000000" and the value field got (on this case) "2*1.6*1*1.25*1.2*1.3*1200000"
5 .... did that or every IF
6 On my case the static entity has the name of LIBS.
7 To get the formula
Getlibs(TextToIdentifier(QuoteDetailTestForm.Record.QuoteDetailTest.LimitofLiability)).libs.value
I created three records to test
Hope that this can help you
Another thing i you don't mind.
In this screen action TowersChange, there is an if statement and two assignments that you do not need.
If this is TRUE
QuoteDetailTestForm.Record.QuoteDetailTest.TowersLiability=True the variable Towers is set to true, and when it is false the variable is false also..
You can simply do this
Towers = QuoteDetailTestForm.Record.QuoteDetailTest.TowersLiability
ActiveTab = "tab-three"
If you need anything more just ask
Carl
You can do also to the ThirdPartyChange screen action.