If Statements in Arcade

4548
1
Jump to solution
01-11-2018 12:38 PM
deleted-user-FTxtuSQd67Ur
New Contributor III

I am working on a script currently in Arcade that is giving me some trouble, although it shouldn't seem like it would. I have a survey where field inspectors go in an log the date that a citation is issued. A person is charged $25 per day for the citation. However, that amount is halted when the inspector issues a completion date.  Therefore I have a conditional statement where, if the closed date is empty, then the person will continue to be charged the $25 on a daily basis until it is closed. If the closed date is filled in, the person will be charged the total from however many days it was from the day the citation started until it closed. Here is what I have right now: (I amusing the "Now" function because I am unsure of how to say if it is "Null" use this)

var open = Date($feature.DateofCitationTag);
var closed = Date($feature.CitationClosed);
var present = Today();
var closedDiff = DateDiff(closed, open, 'days');
var openDiff = DateDiff(present, open, 'days');
var closedAmount = 25 * closedDiff
var openAmount = 25 * openDiff
if (closed <= Now()) {
return "$" + closedAmount
}
else
return "$" + openAmount

The closedAmount shows up and is calculated correctly. However, the openAmount has been giving me a crazy value of $-438380.2083333 when the amount should be $200 (taking into consideration 8 days at $25 per day and counting). I am unsure of why it is acting this way. Anyone have any experience with a conditional statement like this? Thanks!

0 Kudos
1 Solution

Accepted Solutions
KellyHutchins
Esri Frequent Contributor

You can use IsEmpty to check and see if the date is null

var open = Date(2018,01,10);
var closed = null;//Date(2018,01,12);
if(IsEmpty(closed)){
    console("No Closed Date");
}else{
    // closed date listed so calculate fine 
    var closedDiff = DateDiff(closed, open, 'days');
    return "$" + 25 * closedDiff;
}‍‍‍‍‍‍‍‍‍

And as far as the odd results you are getting with DateDiff for open its probably because in Arcade month is 0 based so 0 is January so your calculation may be off by a month. Date Functions | ArcGIS for Developers 

View solution in original post

1 Reply
KellyHutchins
Esri Frequent Contributor

You can use IsEmpty to check and see if the date is null

var open = Date(2018,01,10);
var closed = null;//Date(2018,01,12);
if(IsEmpty(closed)){
    console("No Closed Date");
}else{
    // closed date listed so calculate fine 
    var closedDiff = DateDiff(closed, open, 'days');
    return "$" + 25 * closedDiff;
}‍‍‍‍‍‍‍‍‍

And as far as the odd results you are getting with DateDiff for open its probably because in Arcade month is 0 based so 0 is January so your calculation may be off by a month. Date Functions | ArcGIS for Developers