Parse error: unexpected identifier

3205
1
07-24-2017 01:53 PM
WilliamDigges
New Contributor

Hi all, 

I'm currently trying to write an expression to help code the color of pins for certan adresses with the rules as:

  • If the largest transaction is $1,000+, yellow pin.
  • If the first gift is within the past 18 months (let’s say past 540 days),  blue pin.
  • If the latest transaction amount is greater than 24 months (let’s say 730 days),red pin.
  • All remaining  a white pin.

I wrote two seperate codes to work and each has some errors.  I'm used to Python, but read through Arcade's documentation and couldn't find any help.  My first attempt used multiple if functions, and the second used a when function.  

The first:

if (($feature.Largest_Transaction_Amount) > 999 )

    return ("Yellow")

var datef = Date ($feature.First_Transaction_Date)

var datec = Date ()

if DateDiff (datec, datee,"days") < (541)

    return ("Blue")

var datel = Date ($feature.Latest_Transaction_Date)

if DateDiff (datec, datel, "days") > (729)

    return ("Red")

else

    return ("White")

and the second:

var datef = Date ($feature.First_Transaction_Date)

var datec = Date ()

var datel = Date ($feature.Latest_Transaction_Date)

When (($feature.Largest_Transaction_Amount) > 999, "Yellow",DateDiff (datec, datee,"days") < (541), "Blue",DateDiff (datec, datel, "days") > (719), "Red", 1=1, "White")

I understand there could  be some kinks with the dating, but that is not the main issue.  Any advice for the syntax or any other way to resolve either issue would be appreciated

(As a note, I prefer the second attempt, it could just be the novelty of a the function combining if and elif into a single function, but in the end I just need something that works)

Many thanks 

0 Kudos
1 Reply
KenBuja
MVP Esteemed Contributor

You had some syntax problems in your first expression. Try something like this

if (($feature.Largest_Transaction_Amount) > 999 ) {
    return "Yellow";
}
var datef = Date ($feature.First_Transaction_Date);
var datec = Date ();
if (DateDiff (datec, datee,"days") < 541) {
    return "Blue";
}
var datel = Date ($feature.Latest_Transaction_Date);
if (DateDiff (datec, datel, "days") > 729) {
    return "Red";
} else {
    return "White";
}‍‍‍‍‍‍‍‍‍‍‍‍‍‍‍

I used my dataset with a date with this code as an example

var dateThen = Date($feature.Benthic_Date);
if (DateDiff(Now(), dateThen, 'days') < 40) {
    return "Yellow";
} else {
    return "Blue";
}

to get this map

And this is how it translated to using When

var dateThen = Date($feature.Benthic_Date);
When (DateDiff(Now(), dateThen, 'days') < 40 , "Yellow" , "Blue");
0 Kudos