Reputation: 792
I have a custom record with 3 fields: Minimum Maximum Rate
I would like to build a search that use a number in custom body field and if that number falls between the min and max number it will alert with the rate.
Can I do this via saved search or a scripted search?
Upvotes: 1
Views: 267
Reputation: 15402
Assuming you are using a Client Script for this:
/**
* @NApiVersion 2.x
* @NScriptType ClientScript
*/
define(["N/search"], function(search){
function fieldChanged(ctx){
if(ctx.fieldId == 'custbody_rate_definer'){ // use the id of your custom body field
var definer = ctx.currentRecord.getValue({fieldId:ctx.fieldId});
var rate = null;
// use the actual values from your rate lookup custom record for the search
search.create({
type:'customrecord_custom_rates',
filters:[
['custrecord_max_val', 'greaterthan', definer], 'AND',
['custrecord_min_val', 'lessthan', definer], 'AND',
],
columns:[
'custrecord_rate'
]
}).run().each(function(result){
//this assumes your rates don't overlap and nothing else needs to be done to disambiguate the rate records (e.g. valid during some set of dates)
rate = parseFloat(result.getValue({name:'custrecord_rate'})) || 0;
return false;
});
if(rate) alert('The rate is '+ rate);
}
}
return {
fieldChanged:fieldChanged;
}
});
Upvotes: 1
Reputation: 77
function compare(context){
var minnumber = nlapiGetFieldValue('minnumber');
var maxnumber = nlapiGetFieldValue('maxnumber');
var comparenumber = nlapiGetFieldValue('comparenumber');
var rate = nlapiGetFieldValue('rate');
if(comparenumber > minnumber && comparenumber < maxnumber){
alert(rate);
}
}
Upvotes: 1
Reputation: 8847
filters: [
["thenumberfield", search.Operator.GREATER_THAN, theMinNumber], "AND",
["thenumberfield", search.Operator.LESS_THAN, theMaxNumber]
]
Upvotes: 2