0

I can not get this global function to return useful info....am I missing something?

Hi,

This is my first fucntion...so please be kind! I am calling this function in the product table:

adjustPriceFromEbayUK('UK Price Ebay', "EUR", 'Postage Type (One Item)', "", SKU)

It does not look like it is pulling through the values in the select statements. In the console they are there but the result is always 0.95 (created by the the floor statement at the bottom of the code) when I run it from the form on the Products table. 'UK Price Ebay' value also does not return a value even though it is past in the function header. I think I am fundamentally missing something.

Any thoughts?

Thanks

Matt

function adjustPriceFromEbayUK(ebayUKprice : number,my_currency : text,my_postage_type : text,mySource : text,myProduct : text) do

"---This function takes the eBay UK price and adjusts it for postage type and weight and translates it to other currencies---";
let postage_adjustment := 0;
let myweight := (select Products where SKU = myProduct).'Weight (g)';
if ebayUKprice = null or ebayUKprice < 0.1 then
0
else
"---Add an additional amount based on currency---";
if my_currency = "EUR" or my_currency = "SEK" or my_currency = "CHF" or my_currency = "PLN" then
postage_adjustment = postage_adjustment + 1
end;
if my_currency = "NZD" or my_currency = "JPY" or my_currency = "AUD" or my_currency = "CAD" or my_currency = "USD" then
postage_adjustment = postage_adjustment + 2
end;
"---Add an additional amount based on postage type---";
if my_postage_type = "Parcel" then
postage_adjustment = postage_adjustment + 2
end;
if my_postage_type = "Large Letter (Heavy)" then
postage_adjustment = postage_adjustment + 1
end;
"---Add an additional amount based on weight---";
if myweight = null then myweight = 0 end;
if myweight > 0 and myweight <= 50 then
postage_adjustment = postage_adjustment + 0
end;
if myweight > 50 and myweight <= 150 then
postage_adjustment = postage_adjustment + 0
end;
if myweight > 150 and myweight <= 350 then
postage_adjustment = postage_adjustment + 0
end;
if myweight > 350 and myweight <= 600 then
postage_adjustment = postage_adjustment + 0
end;
if myweight > 600 and myweight <= 1000 then
postage_adjustment = postage_adjustment + 0
end;
if myweight > 1000 and myweight <= 1500 then
postage_adjustment = postage_adjustment + 0
end;
if myweight > 1500 and myweight <= 2000 then
postage_adjustment = postage_adjustment + 0
end;
"---Adjust the final total by the currency variable---";
let x_rate := first(select Currencies where Currency = my_currency).'Exchange Rate';
let result := ebayUKprice + postage_adjustment;
floor(result * x_rate)+0.95
end
end

12 replies

null
    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Matthew

    First.. This line looks suspect

    let myweight := (select Products where SKU = myProduct).'Weight (g)';

     

    it will return an array of weights.. might need a "first" there. 

    Next .. the magic must be in these three lines. 
    let x_rate := first(select Currencies where Currency = my_currency).'Exchange Rate';
    let result := ebayUKprice + postage_adjustment;
    floor(result * x_rate)+0.95

    Either x_rate is zero, result is zero ... or (resut * x_rate) yields something less than 1. 

    Try this.. First.. replace floor(result * x_rate)+0.95

    with 

    x_rate

     

    What did you get?   Then repeat with result... and then with floor(result*x_rate) .. 
     

    • Luck and Luck
    • Matthew_Luck
    • 4 yrs ago
    • Reported - view

    Hi,

    Thank you for the input.

    x_rate = null

    result = ebayUKprice (no postage adjustment)

    so x_rate and postage_adjustment are not working

    Any ideas?

    Matt

    • Luck and Luck
    • Matthew_Luck
    • 4 yrs ago
    • Reported - view

    Hi, The field in the x_rate is a combo...does it need a text() around it? Cheers

    • Luck and Luck
    • Matthew_Luck
    • 4 yrs ago
    • Reported - view

    Hi, OK the x_rate is working, your comment about the array of weights made me think...but postage_adjustment is not.

    Cheers

    • Luck and Luck
    • Matthew_Luck
    • 4 yrs ago
    • Reported - view

    Hi, OK the x_rate is working, your comment about the array of weights made me think...but postage_adjustment is not.

    Cheers

    • Luck and Luck
    • Matthew_Luck
    • 4 yrs ago
    • Reported - view

    Weight and the variables passed in the function (my_currency and my_postage_type ) all show if they are the result of the function.

    • Luck and Luck
    • Matthew_Luck
    • 4 yrs ago
    • Reported - view

    Hi, OK I have taken the function to bere bones and it still returns 0!

    function adjustPriceFromEbayUK(ebayUKprice : number,my_currency : text,my_postage_type : text,mySource : text,myProduct : text) do
    let postage_adjustment := 0;
    "---Add an additional amount based on currency---";
    if my_currency = "EUR" then
    postage_adjustment = 1
    end;
    postage_adjustment
    end

    • Mconneen
    • 4 yrs ago
    • Reported - view

    postage_adjustment = 1

     

    should be 

    postage_adjustment := 1

    • Mconneen
    • 4 yrs ago
    • Reported - view

    Sorry.. did not catch that in your first post of the funtion. :(    But I guess that is how we learn.. make a mistake.. tear it down.. and build it back up.. 

    if my_currency = "EUR" or my_currency = "SEK" or my_currency = "CHF" or my_currency = "PLN" then
    postage_adjustment = postage_adjustment + 1
    end;

     

    should be

    if my_currency = "EUR" or my_currency = "SEK" or my_currency = "CHF" or my_currency = "PLN" then
        postage_adjustment := postage_adjustment + 1
    end;

    • Luck and Luck
    • Matthew_Luck
    • 4 yrs ago
    • Reported - view

    Hi, Thank you. Do you always use := when assigning a new value to a variable or is it just because I and referencing itself in the answer? Thanks Matt

    • Luck and Luck
    • Matthew_Luck
    • 4 yrs ago
    • Reported - view

    Hi, One last thing. I have these values on more than one form (one is an input form and the other an export form). When will the info populate from one to the other? Also, if I change the exchange rate, when will all the pricing update on the product table? When the export is run or if a user accesses the product...which ever comes first...or does something run in the background? thanks Matt

    • Mconneen
    • 4 yrs ago
    • Reported - view

    @Matt, 

    Yes..  :=  is for assignment ....  =    is for equality check .. 

     

    As for your other questions... Hard to answer without seeing your data model ..    Ninox does run some open office hours (I think via facebook) .. or you can send them a note to support@ninox.com  to schedule some time with them.. They have been most helpful. 

     

    OR.. post your data model / logic here .. and let's see how it goes. :) 

Content aside

  • 4 yrs agoLast active
  • 12Replies
  • 1221Views