Pregunta

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!
}
¿Fue útil?

Solución

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;
}
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top