trying to compare the price level on a customer re...
# suitescript
m
trying to compare the price level on a customer record which is of type object and the price level on transaction line which is of string. Tried parseInt & JSON.stringify to compare both variables but neither worked - anything else I can try?
Ex (inside validateLine function) var customer_pl_id = parseInt(customer_pl);             var price_level_id = parseInt(price_level);             alert("Type: " + typeof(customer_pl_id));             alert("Type: " + typeof(price_level_id));             if (price_level_id === customer_pl_id) {                 alert("Match");             }             else {                 alert("No Match")                 return false;             } Both Values = 122 Both Type = number But it hits the if statement instead of else.
e
I'm confused; if
price_level_id
and
customer_pl_id
are both
122
, then you should hit the
if
, not the
else
I don't see how it's possible to hit the
else
given your statements. If that's the entirety of your
validateLine
, then I'd expect you would see an alert with
Match
and then the line would not commit since you are not returning
true
anywhere
m
Copy code
function validateLine(context) {
            var transaction = context.currentRecord;
            /**Screen Messages**/
            var new_price_level = {
                title: 'PRICE LEVEL CHANGES',
                message: 'Price Level must not be different to the price level set on the customer record.'
            };

            var entity_id = transaction.getValue({
                fieldId: 'entity'
            });

            var customer_pl = search.lookupFields({
                type: search.Type.CUSTOMER,
                id: entity_id,
                columns: 'pricelevel'
            });
            alert(customer_pl.pricelevel[0].value);

            var price_level = transaction.getCurrentSublistValue({
                sublistId: "item",
                fieldId: "price",
            });

            alert( price_level);

            var customer_pl_id = parseInt(customer_pl);
            var price_level_id = parseInt(price_level);

            if (price_level_id === customer_pl_id) {
                alert("Match");
            }
            else {
                alert("No Match")
                return false;
            }

            return true;
        }
that's the full function - I am confused why the two values are not equal
c
You never assigned the value of customer_pl to the value returned in the lookup. You do an alert for it but thats it. So its still an object which is why its not gonna be equal.
👍 1
Copy code
var customer_pl_id = parseInt(customer_pl.pricelevel[0].value);
var price_level_id = parseInt(price_level);
m
ahhhh! thanks for that