function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
sbooth1440sbooth1440 

Updating AMOUNT field in Opportunities with a calculated field

Hi All!  I have the need to update the AMOUNT field in an Opportunity with a calculated field.  The Amount field is not natively a calculated field.  I searched for assistance in help and found a solution on the site (listed below).  This solution also had a word document attached that had the HTML required for this S-Control.  I did the following:
 
1.  I already had the calculated field called "Total Opportunity" created and it is working fine.
2.  I created the S-Control and pasted in the HTML from the solution I found.  I changed the field name in the HTML to my field name for Total Opportunity. (total_opportunity_value_c) in the code.
3.  I changed the page layout to embed the S-Control (and then tried a button, and then a customer link).
 
Unfortunately in all situations I did get a window saying "Updating Amount Field" (that's driven from the HTML) but it just hangs there and doesn't do anything.  My assumption is that it's an error in the HTML but, as me not being a coder, I can't debug.  Anyone out there able to quickly eyeball and see where there may be an issue? 
 
Also - is there a way for me to send the "fix", if I get one, back to SF.com so that this solution on their site is actually correct????
 
Thanks to all in advance!!!!!!
 
Here is the "solution" found on sf.com:
*********************************************************************************************
The definition behind the native Opportunity Amount field does not allow for the creation of a formula field. As a result, the amount field on opportunities cannot be a calculated value based upon other fields on the Opportunity record.

The Solution is as follows:

1. Create a custom field on the Opportunity to perform the requested calculation.
2. Create an S-Control that edits the Opportunity, placing the custom field's value (the one created in step 1) into the Amount field on the Opportunity.
3. Create a custom link or formula field (see below) that will invoke the S-Control when clicked.

- Sample code has been provided for the S-Control in Step 2 in the "Attachments" section of this record. (NOTE: Replace the merge field {!Opportunity_Requested_Price} in the provided code with the calculated field in your Opportunity configuration (step 1)).

- Additionally, the following is an example of a formula field that will invoke a given scontrol:

HYPERLINK("/servlet/servlet.Integration?lid=01N30000000D0vg&eid="&{!Id}, "Update" )
(NOTE: The record ID in the above should be replace the record ID of your S-Control, created in step 2).
**********************************************************************************************************************************
Here is the HTML (I did replace my calculated field name): 
 

Solution: Update Opportunity Amount Field With a Calculated Value

Owner: Chris Morgan

 
Process to create the S-Control discussed in Step 2 of this solution:
 <HTML> 
<HEAD>
<TITLE>Status...</TITLE>
</HEAD>
<center>
<table width="100%">
<tr>
<td align=center>
<span class="moduleTitle"><h4>Updating ''Amount'' field<Br>Please wait...</span>
</h4></td>
</tr>
<tr>
<td align=center>
<img src="/img/waiting_dots.gif" border="0" width=156 height=34>
</td>
</tr>
</table>
</center>

<script language="JavaScript">
setTimeout("",5000);
window.parent.opener.location="/{!Opportunity.Id}/e?retURL=%2F{!Opportunity.Id}&opp7={!Opportunity.total_opportunity_value__c}&save=1";
setTimeout("window.close();", 5000);
</script>
</HTML>
CrmzepherCrmzepher

Hello,

I played around with this exact problem for quite some time and discovered that it was better to rethink how I wanted the Amount field to be updated. In the Professional version you can not apply any type of formula to the Amount field. So you have to create another field, formula field that contains the "actual" amount that you want to be placed in the Amount field. This custom formula field I passed exactly under the standard Amount field, called Amount Formula Result.

Once you have done that I found that it was best to create a custom button that becomes part of the workflow process for the employee responsible for initial review of teh Opp to click that would compare the two values, the Amount field and the Amount Formula Field, and update the Amount field should they be different.

This is a great solution for several reasons. 1. The auto-refresh scontrol you describe above has a good number of problems of timing out before updating. Also in professional version only a Sys Admin has the rights/ability to update the standard field via the scontrol. I fought SF on that point for quite some time. Finally once you deploy to more than 10 users it starts to cause latency problems throughout the network.

But probably why it is a fantastic solution is that you can begin to create a true workflow / Opp field validation process by coding the "Update Opp Amount" button with basic javascript that only allows certain users to be able to activate the button.

Here is an example of the code . . .

// Check the roles allowed to do this
var myrole = "{!$UserRole.Name}";
var auth = 'no';

if(myrole == 'Marketing Manager' || myrole == 'Client Services Manager' || myrole == 'Client Services Assistant Manager' || myrole == 'Client Services Admin' || myrole == 'CRM Manager' || myrole == 'Broker Sales Manager' || myrole == 'Broker Spanish Country Manager' || myrole == 'Broker Dubai Country Manager' || myrole == 'Broker Turkey Country Manager' || myrole == 'Broker Bulgaria Country Manager' || myrole == 'Finance Executive' || myrole == 'Finance Manager'){auth='yes';}

if (auth=='no')
{alert('You are not authorized to Update the Amount. This will be done by your Manager.');}
else
{
var theformula = "{!Opportunity.Amount_Formula_Result__c}";
var theamount = "{!Opportunity.Amount}";

// If they are not the same (which they should be) then enter here
if(theformula != theamount)
{
// Loop across the formula field and remove anything thats not a number, comma or full stop
for (var i=0, currencyasnumber ='', valid="1234567890.,"; i<theformula .length; i++)
if (valid.indexOf(theformula .charAt(i)) != -1)
currencyasnumber += theformula .charAt(i);

{navigateToUrl('/{!Opportunity.Id}/e?retURL=%2F{!Opportunity.Id}&opp7=' + currencyasnumber + '&save=1')}
}
}
 
Hope this helps!! Good luck.
 
crmzepher


Message Edited by Crmzepher on 04-16-2008 04:06 PM
sbooth1440sbooth1440
Thank you!!!!!!!!!!!!!!!