- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 04:12 AM
Looking to know how to write the code/rule for the following:
Need to order is a formula field that describes the need to order Assets to the maximum level once they have dropped below the min.
Scenario 1:
“Min” = 5, “Max” = 10, “quantity in stock” = 6, “need to order” = no, “quantity to order” = 0 – This is because the quantity in stock is above the Min
Scenario 2:
“Min” = 5, “Max” = 10, “quantity in stock” = 4, “need to order” = yes, “quantity to order” = 6 – This is because the quantity in stock dropped below the min and we need to order to the maximum level
EX:
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 09:16 AM
You can try the below script :
On change script : with onchange of field : Quantity max
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var qinstock = g_form.getValue('quantity_in_stock');
alert(qinstock);
var qmin = g_form.getValue('quantity_min');
alert(qmin);
var qmax = g_form.getValue('quantity_max');
alert(qmax);
var quantitytoorder = qmax - qinstock;
alert(quantitytoorder);
if (qinstock < qmin) {
alert(quantitytoorder);
g_form.setValue('need_to_order', 'yes');
g_form.setValue('quantity_to_order', quantitytoorder);
}
else{
g_form.setValue('need_to_order', 'no');
g_form.setValue('quantity_to_order', 0);
}
//Type appropriate comment here, and begin script below
}
Thanks and Regards
Sai Venkatesh
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
07-16-2024 09:16 AM
You can try the below script :
On change script : with onchange of field : Quantity max
function onChange(control, oldValue, newValue, isLoading) {
if (isLoading || newValue == '') {
return;
}
var qinstock = g_form.getValue('quantity_in_stock');
alert(qinstock);
var qmin = g_form.getValue('quantity_min');
alert(qmin);
var qmax = g_form.getValue('quantity_max');
alert(qmax);
var quantitytoorder = qmax - qinstock;
alert(quantitytoorder);
if (qinstock < qmin) {
alert(quantitytoorder);
g_form.setValue('need_to_order', 'yes');
g_form.setValue('quantity_to_order', quantitytoorder);
}
else{
g_form.setValue('need_to_order', 'no');
g_form.setValue('quantity_to_order', 0);
}
//Type appropriate comment here, and begin script below
}
Thanks and Regards
Sai Venkatesh