I am having a issue with a formula field, I am get...
# suitescript
d
I am having a issue with a formula field, I am getting a invalid expression. I am not sure if it because I need to CAST my result as a string. Formula is in thread.
This doesn’t work
Copy code
CASE WHEN {custrecord_mro_scale_scale_item.weight} != 0
THEN
    CASE {custrecord_mro_scale_scale_item.weightunit}
    WHEN 'lb' THEN ({custrecord_mro_scale_scale_currentreadin.custrecord_mro_scale_scalereading_value}/{custrecord_mro_scale_scale_scaletype.custrecord_mro_scale_scaletype_factor})/({custrecord_mro_scale_scale_item.weight}*453.592)
    WHEN 'oz' THEN ({custrecord_mro_scale_scale_currentreadin.custrecord_mro_scale_scalereading_value}/{custrecord_mro_scale_scale_scaletype.custrecord_mro_scale_scaletype_factor})/({custrecord_mro_scale_scale_item.weight}*28.3495)
    WHEN 'kg' THEN ({custrecord_mro_scale_scale_currentreadin.custrecord_mro_scale_scalereading_value}/{custrecord_mro_scale_scale_scaletype.custrecord_mro_scale_scaletype_factor})/({custrecord_mro_scale_scale_item.weight}*1000.00)
    WHEN 'g' THEN ({custrecord_mro_scale_scale_currentreadin.custrecord_mro_scale_scalereading_value}/{custrecord_mro_scale_scale_scaletype.custrecord_mro_scale_scaletype_factor})/({custrecord_mro_scale_scale_item.weight})
    ELSE
    'ERROR: NO WEIGHT UOM'
    END
ELSE
'ERROR: NO ITEM WEIGHT'
END
This does work
Copy code
CASE WHEN {custrecord_mro_scale_scale_item.weight} != 0
THEN
    CASE {custrecord_mro_scale_scale_item.weightunit}
    WHEN 'lb' THEN '453.592'
    WHEN 'oz' THEN '28.3495'
    WHEN 'kg' THEN '1000'
    WHEN 'g' THEN '1'
    ELSE
    'ERROR: NO WEIGHT UOM'
    END
ELSE
'ERROR: NO ITEM WEIGHT'
END
m
I would typically debug a complicated formula by breaking it into parts and trying each part.
For example does just
({custrecord_mro_scale_scale_currentreadin.custrecord_mro_scale_scalereading_value}/{custrecord_mro_scale_scale_scaletype.custrecord_mro_scale_scaletype_factor})/({custrecord_mro_scale_scale_item.weight}*453.592)
work?
If there are possible 0's anywere you could have division by zero issues. If the problem is numeric result in a string field you might need to wrap in
TO_CHAR()
s
depending on volume, maybe switch some of that complexity to code rather than stuffing it all in the search itself?
m
Where's the fun in that 😜
d
@michoel Yes just that section works
m
Then try the other three individually
d
@michoel all the others work
t
They are tested with the full formula? Case When != 0 then case when.... individually?
d
I just tested the forumlas independently and removed the case statements…. I will now test removing the last case statement… but I am not sure how that will really make a difference
apparently that does make a difference
t
netsuite
d
unfortunately it really doesn’t get me much closer to a solution 😞
grrrrrr
it is a casting error
m
Did you try
TO_CHAR()
?
s
you guys are kinda making my point here 😉
😆 1
p
All
then
results have to be the same datatype. You are mixing datatypes