You need to sign in to do that
Don't have an account?
James_Adapx
JavaScript error
I get the error "Opportunity is Undefined" when clicking this button. So I am trying to pass in the Opportunity Id so that I can pull information out of that Opprotunity..
Here is the javascript
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var accts = sforce.apex.execute("sumTotal","getTotal", {arg:!Opportunity.Id});
Here is the class I am calling
global class sumTotal{
WebService static double getTotal(Id optid){
Opportunity opt = [select Id, Name, shipping_method__c, accountid from Opportunity where Id=: optid];
ShipCode__c code = [select id, Is_USPS__c, USPS_Service_Name__c from ShipCode__c where USPS_Service_Name__c =: opt.shipping_method__c];
Account accnt_info = [select shippingpostalcode,billingpostalcode from account where id=:opt.accountid];
double total_shipping_charge=0;
Opportunity opt = [select Id, Name, shipping_method__c, accountid from Opportunity where Id=: optid];
ShipCode__c code = [select id, Is_USPS__c, USPS_Service_Name__c from ShipCode__c where USPS_Service_Name__c =: opt.shipping_method__c];
Account accnt_info = [select shippingpostalcode,billingpostalcode from account where id=:opt.accountid];
double total_shipping_charge=0;
The syntax of a merge field in an s-control is:
"{!something}"
So, I think you want:
var OppId = "{!Opportunity.Id}"; var accts = sforce.apex.execute("sumTotal","getTotal", {arg:OppId});
I think that if you did a "View Source" and looked at the line in question, you'd be able to see that the substitution wasn't done properly when the code for your page was generated.
Best, Steve.
p.s. I also think your queries might be tighter in your Apex code. Couldn't you pull the account information in the same query as the Opportunity information?
Message Edited by SteveBower on 11-04-2008 12:18 AM
{!REQUIRESCRIPT("/soap/ajax/10.0/connection.js")}
{!REQUIRESCRIPT("/soap/ajax/10.0/apex.js")}
var opt = {!Opportunity.Id};
var accts = sforce.apex.execute("sumTotal","getTotal", {arg:opt});