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
alexannicalexannic 

BUG: Setting Sales Price not possible in OpportunityLineItem - Help needed!

Hello,
I am trying to write a small S-Control which allows the user to specify a quantity and UnitPrice (or SalesPrice) in an Opportunity Line Item.

However, when the user enters a different quantity than the current one and changes the sales price, the s-control completely ignores the specified SalesPrice. Instead, it calculates what the sales price should be with the new quantity so that the old Total Price is kept the same!

Example:
if an existing Opportunity line Item has the following values:
Quantity: 3, SalesPrice 10, and TotalPrice 30 (3x10=30)
and I change the Quantity to 2, and SalesPrice to something else, say 11.28, the values become:
Quantity: 2, SalesPrice 15, and TotalPrice 30 (2x15=30 again, instead of 2x11.28=22.56)

Here is sample source Code illustrating this behaviour:
Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Edit OppLine</title>
<script src="/soap/ajax/8.0/connection.js" type="text/javascript"></script>

<script language="javascript">
var OpplineID = "00k200000024JF4"
function initPage() {
 sforce.connection.query("Select o.Opportunity.Id, o.Opportunity.Name, o.Id, o.ListPrice, o.Quantity, o.TotalPrice, o.UnitPrice from OpportunityLineItem o WHERE Id = '"+OpplineID+"'", {
      onSuccess : ReadCode,
      onFailure : failure
    });
}
function ReadCode(FaseisQueryResult){
 
 var oItems = FaseisQueryResult.getArray("records");
 
 if (oItems.length > 0) {
  for (var x = 0; x < oItems.length ; x++) { 
   var Code = oItems[x];
   var ID = Code.Id;
   var ListPrice = Code.ListPrice;
   var TotalPrice = Code.TotalPrice;
   var Quantity = Code.Quantity;
   var SalesPrice = Code.UnitPrice;
  
  }
 }
 
 var opp = new sforce.SObject("OpportunityLineItem");
 opp.id = OpplineID;
 opp.Quantity = "3";
 opp.UnitPrice = "11.28";
    
 //now save
 resulte = sforce.connection.update([opp]);
 window.parent.opener.location = "/"+OpplineID; 
 window.close(); 
 return false; 
  
}


 function failure(error) {
    alert(error);
  }

</script>
</head>
<body onload="initPage();">
</body>
</html>

 

To use the above code, replace the OpplineID variable with a valid OpportunityLineItem ID from your organisation.

Any help will be greatly appreciated, as I'm really stuck at the moment!
Thanks.
 


Message Edited by alexannic on 04-05-2007 04:00 AM

CaptainObviousCaptainObvious
original opplineitem:
 
Quantity 3.00
Sales Price $10.00
Total Price $30.00
 
after your code:
 
Quantity 2.00
Sales Price $11.28
Total Price $22.56
 
( you had opp.Quantity = "3"; in your code, i changed that to a "2" to make the quantity different)
 
It looks like it's doing what it's supposed to do. Is there something else in your script that could be creating a conflict?
alexannicalexannic
Thanks for the reply!
Well my code actually calculates the Sales Price minus a discount (which is stored in a custom field), but that's a simple math formula.

Good news though:
The problem is solved if I set quantity & Total Price and not quantity and SalesPrice!

I am sure this is a bug, because I certainly do not have any code in my S-control to set the Sales Price to a value which will compensate for the change in quantity so that the total stays the same! By the way, same behaviour observed in vb .net with the API.

Thanks for the help anyway..
Alex