I am trying to return the number of products of with the ProductName = EAP related to an Opportunity. Here is my code:
function getProductTypes (oppId) {
var result = sforce.connection.query("Select COUNT() From OpportunityLineItem where OpportunityId = '" + oppId + "' and PricebookEntry.Product2.Name IN ('EAP') ");
return result;
}
What I want to do is return the number of number of "EAP" products related to the opportunity so then in the below code block, I can determine another piece of code to run:
if(getProductTypes('{!Opportunity.Id}') >= 1){
//run this code!
}else{
//run this code instead!
}
In case of doubt - alert()
or console.log()
is your best friend ;) Closely followed by specification of the QueryResult object (it's in different document than the AJAX toolkit developer guide...)
This should work:
function getProductTypes (oppId) {
var result = sforce.connection.query(...);
alert(result); // remove it once you're happy
return result == null ? 0 : result.size;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.