Scenario:
Create a saved search for listing the rate card price of a specific billing class with a specific currency. Eg: if the billing class is ‘Consultant’ and the preferred currency is US Dollars, search result should be the corresponding currency value.
Solution:
/**
* Function to check the price of the rate card.
*
* @param {genericBillingClass} genericBillingClass - fieldValue
* @param {rateCardId} rateCardId - fieldValue
* @param {prjCurrency} prjCurrency - fieldValue
* @returns {res} res - result
*
* @since 2015.2
*/
function rateCardSearch(genericBillingClass,rateCardId,prjCurrency){
try{
if(checkForParameter(genericBillingClass)==true&&checkForParameter(rateCardId)==true&&checkForParameter(prjCurrency)==true){
var billingratecardSearchObj = search.create({
type: "billingratecard",
filters:
[
["currency","anyof",prjCurrency],
"AND",
["internalid","anyof",rateCardId],
"AND",
["billingclass","anyof",genericBillingClass],
"AND",
["effectivedate","onorbefore","today"],
"AND",
[["enddate","onorafter","today"],"OR",["formuladate: {enddate}","isempty",""]]
],
columns:
[
search.createColumn({
name: "name",
summary: "MAX",
sort: search.Sort.ASC,
label: "Name"
}),
search.createColumn({
name: "price",
summary: "MAX",
label: "Price"
})
]
});
var searchResultCount = billingratecardSearchObj.runPaged().count;
var res= []
billingratecardSearchObj.run().each(function(result){
// .run().each has a limit of 4,000 results
var name = result.getValue({
name: "name",
summary: "MAX",
sort: search.Sort.ASC
})
var price = result.getValue({
name: "price",
summary: "MAX"
})
res.push({
name: name,
price: price
})
return true;
});
}
return res
}
catch (e) {
console.log("Error @ ratecard Search: ",e.name+": "+e.message)
}
}