Answered by:
Calculated field on OnChange() in form

Question
-
Hi,I'm new to Dynamics CRM, and can't easily find a solution (google, forums, blogs) on how to perform the following:1. I have in the form "Quote Product" a field called "Discount Percentage" and another field "Discount Amount". Now, when I enter e.g. 3 in the field "Discount Percentage", the field "Discount Amount" has to be calculated, based on the value in "Price per Unit". Eg. when "Price per unit" is 25, and I give 2% discount, the field "Discount Amount" should be calculated to 24,5.2. An alternative solution is that I would have a the following control using radio buttons:[ ] Discount Percentage [________][*] Discount Amount [_________]When the user selects the radio button for "Discount Percentage" the "Discount Amount" becomes read only, and is automatic calculated. Similar when the user sleects the radio button for "Discount Amount", then discount percentage is calculated.Any hints are welcome :)Tuesday, March 2, 2010 9:14 AM
Answers
-
locusta read this its same thing but related to "Opportunity Product"
http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/c3a8df47-e898-4f5a-98ff-9bf7eee463d8/#40edd16e-05a0-444c-ad3a-feccb68f489b
http://www.allaboutdynamics.com- Marked as answer by DavidJennawayMVP, Moderator Tuesday, April 13, 2010 2:37 PM
Tuesday, March 2, 2010 10:04 AM -
Hi
your sample code may be as below.
1. I have in the form "Quote Product" a field called "Discount Percentage" and another field "Discount Amount". Now, when I enter e.g. 3 in the field "Discount Percentage", the field "Discount Amount" has to be calculated, based on the value in "Price per Unit". Eg. when "Price per unit" is 25, and I give 2% discount, the field "Discount Amount" should be calculated to 24,5.
Onchange Event of Discount Percentage:
crmForm.all.new_DiscountAmount.DataValue = crmForm.all.new_Priceperunit.DataValue - ((crmForm.all.new_Priceperunit.DataValue)*(crmForm.all.new_Discountpercentage.DataValue)/100);
2. An alternative solution is that I would have a the following control using radio buttons:[ ] Discount Percentage [________][*] Discount Amount [_________]When the user selects the radio button for "Discount Percentage" the "Discount Amount" becomes read only, and is automatic calculated. Similar when the user sleects the radio button for "Discount Amount", then discount percentage is calculated.
if (crmForm.all.new_Discountpercentage.DataValue == 0)
{
crmForm.all.new_DiscountAmount.DataValue =<<your calculation>>;
crmForm.all.new_DiscountAmount.readOnly = true;
crmForm.all.new_DiscountPercentage.readOnly = false;
}
else
{
crmForm.all.new_Discountpercentage.DataValue =<<your calculation>>;
crmForm.all.new_Discountpercentage.readOnly = true;
crmForm.all.new_DiscountAmount.readOnly = false;
}
Regards
Vinoth- Proposed as answer by VinothBalasubramanian Tuesday, March 2, 2010 10:11 AM
- Marked as answer by DavidJennawayMVP, Moderator Tuesday, April 13, 2010 2:37 PM
Tuesday, March 2, 2010 10:11 AM
All replies
-
Tuesday, March 2, 2010 10:00 AM
-
locusta read this its same thing but related to "Opportunity Product"
http://social.microsoft.com/Forums/en-US/crmdevelopment/thread/c3a8df47-e898-4f5a-98ff-9bf7eee463d8/#40edd16e-05a0-444c-ad3a-feccb68f489b
http://www.allaboutdynamics.com- Marked as answer by DavidJennawayMVP, Moderator Tuesday, April 13, 2010 2:37 PM
Tuesday, March 2, 2010 10:04 AM -
Hi
your sample code may be as below.
1. I have in the form "Quote Product" a field called "Discount Percentage" and another field "Discount Amount". Now, when I enter e.g. 3 in the field "Discount Percentage", the field "Discount Amount" has to be calculated, based on the value in "Price per Unit". Eg. when "Price per unit" is 25, and I give 2% discount, the field "Discount Amount" should be calculated to 24,5.
Onchange Event of Discount Percentage:
crmForm.all.new_DiscountAmount.DataValue = crmForm.all.new_Priceperunit.DataValue - ((crmForm.all.new_Priceperunit.DataValue)*(crmForm.all.new_Discountpercentage.DataValue)/100);
2. An alternative solution is that I would have a the following control using radio buttons:[ ] Discount Percentage [________][*] Discount Amount [_________]When the user selects the radio button for "Discount Percentage" the "Discount Amount" becomes read only, and is automatic calculated. Similar when the user sleects the radio button for "Discount Amount", then discount percentage is calculated.
if (crmForm.all.new_Discountpercentage.DataValue == 0)
{
crmForm.all.new_DiscountAmount.DataValue =<<your calculation>>;
crmForm.all.new_DiscountAmount.readOnly = true;
crmForm.all.new_DiscountPercentage.readOnly = false;
}
else
{
crmForm.all.new_Discountpercentage.DataValue =<<your calculation>>;
crmForm.all.new_Discountpercentage.readOnly = true;
crmForm.all.new_DiscountAmount.readOnly = false;
}
Regards
Vinoth- Proposed as answer by VinothBalasubramanian Tuesday, March 2, 2010 10:11 AM
- Marked as answer by DavidJennawayMVP, Moderator Tuesday, April 13, 2010 2:37 PM
Tuesday, March 2, 2010 10:11 AM -
Thank you guys for the quick responseOne step closer to becoming the next CRM guru :)Tuesday, March 2, 2010 10:18 AM