Answered by:
How to override onSave formula of Opportunity Product to get overridden value of Extended Amount?

Question
-
On opportunity product I get following 3 fields:
Amount
Manual Discount
Extended Amount
On formSave() event it saves data in DB using following formula:
Extended Amount = Amount - Manual Discount
Now I've added another expense with few of the prodcuts i.e. Expense 2. Expense 2 doesn't come with every product, so i've used javascript to show/hide its textbox. Plus i've added javascript on all Amount, Manual Discount and Expense 2 Fields and onSave() event of Form as following:
Extended Amount = Amount - Manual Discount + Expense2
Issue: When I try to Save Form, it saves successfully but ignores Expense2 and uses its own forumla : Extended Amount = Amount - Manual Discount. Is there any way to override CRM's own formula? I can use workflow for this task but using workflow doesn't update DB immidiately, which could result in user frustrations.
Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.comThursday, August 6, 2009 6:22 AM
Answers
-
Hi,
Please see blog explains how to Override price - opportunity
Thanks,
product
http://aadreja.blogspot.com/2009/07/override-price-opportunity-product.html
Mayank- Marked as answer by Sohaib [CRM Professional] Wednesday, August 12, 2009 4:53 AM
Tuesday, August 11, 2009 8:15 AM
All replies
-
No, there is no supported way to override this formula.
I'm not sure if there is any unsupported way either.
This has been addressed as a feature wanted in the next version of CRM.
Best Regards Jens Egil Evensen- Edited by Jens Egil Evensen [CGI] Thursday, August 6, 2009 7:52 AM error in signature
- Proposed as answer by Jens Egil Evensen [CGI] Thursday, August 6, 2009 7:52 AM
Thursday, August 6, 2009 7:52 AM -
Hi,First, there are always unsupported ways, if everything else fails, database triggers can save you.Second, this is not the case. If your workflow is working correctly, and all you worry about is the bad users exprience of seeing something on screen that is differnt than the real value in the database, just use javascript onload to calculate your on desired value, and show it the Extended Amount field.Third, cant you use a precreate plugin for this?Good luck.Thursday, August 6, 2009 12:12 PM
-
Moti: Precreate will not do this for you.
The system will calculate the value by it's own fomula no matther what way you change it. Even if you change it directly in the database.
Javascript might do the trick for the user, but then the recalculate function in the opportunity will show the wrong value anyway.
Believe me, all options (that I can think of anyway) have been tried.
If you have a solution you can demonstrate it would be very welcome.
Best Regards Jens Egil EvensenThursday, August 6, 2009 12:16 PM -
Hello all,
then what workaround will you suggest me if i want to add a new variable expense with few of products (not all)?
Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.comThursday, August 6, 2009 5:49 PM -
* Jens:The thing is, that opportunity has a quirky behavior. It recalculates the estimated value every time the opportunity is being retrieved (why on earth did they do that?).However, this just complicates things, but its still possible, just very messy.
- Triggers - you need two triggers. One for opportunityproduct (delete, create, insert) that preforms your custom calculations, and update both the extended amount of the specific product, and the total estimated value of its opportunity.
The second trigger should be on opportunity itself (update). Whenever you update the opportunity, it should recalculate the custom calculation and update the opportunity accordingly.
Make sure you use @@NestLevel since one trigger WILL trigger the other. - Plugins - You can similar solutions, but with plugins for better code maintenance. The opportunityproduct plugin should be activated on post [create, update, delete] and use sql query to preform the custom calculations.
The opportunity plugin should run on Retrieve and both update the estimated value (again, sql query), and replace the ~wrong~ value in the DynamicEntity.
I'll try to post code for either solution later on, but i can't promise when i'll get to it.@Sohaib.Try to implement the solutions i specified above. The new field should be handled within the UI (js) and you should not care in your calculations what product was it (regard it as zero if it should not be included in the calculations).Regads,MotiThursday, August 6, 2009 8:59 PM - Triggers - you need two triggers. One for opportunityproduct (delete, create, insert) that preforms your custom calculations, and update both the extended amount of the specific product, and the total estimated value of its opportunity.
-
If you can't act on the extended amount, perhaps you could act on the manual discount figure, adjusting it to account for the expense and relabel it to reflect what it represents.Leon Tribe
Want to hear me talk about all things CRM? Check out my blog
http://leontribe.blogspot.com/or hear me tweet @leontribe
Want to hear me talk about all things CRM? Check out my blog http://leontribe.blogspot.com/ or hear me tweet @leontribe- Proposed as answer by Leon TribeMVP Monday, August 10, 2009 9:31 PM
Monday, August 10, 2009 9:31 PM -
Hi,
Please see blog explains how to Override price - opportunity
Thanks,
product
http://aadreja.blogspot.com/2009/07/override-price-opportunity-product.html
Mayank- Marked as answer by Sohaib [CRM Professional] Wednesday, August 12, 2009 4:53 AM
Tuesday, August 11, 2009 8:15 AM -
Mayank,
Suggested link helped alot. I did the same trick using JavaScript using a custom manual discount field on form. Now my issue is to hide actual manualdiscountamount field from the FORM. If i remove it from form, i can't set its value using javascript.
If i hide manualdiscountamount field using javascript, can it work?
Sohaib Ahmad [Business Management Solution Professional] http://www.solutiontalk.blogspot.comWednesday, August 12, 2009 10:15 AM