[英]Returning Count() from SOQL Query in a Javascript Function
I am trying to return the number of products of with the ProductName = EAP related to an Opportunity. 我正在尝试返回与商机相关的ProductName = EAP的产品数量。 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: 我想要做的是返回与机会相关的“ EAP”产品的数量,因此,在下面的代码块中,我可以确定要运行的另一段代码:
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...) 如有疑问
alert()
或console.log()
是您最好的朋友;)紧随其后的是QueryResult对象的规范(与AJAX工具包开发人员指南位于不同的文档中...)
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;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.