Select to view content in your preferred language

Smart Forms - Calculated Date Field - Unexpected Result

182
6
Jump to solution
Thursday
Labels (1)
jessneuner
Frequent Contributor

Hello!

Not sure if it's me or something else on this one, but I need your help! For our workflow, I want to populate a date field with the current date and time IF (1) it should be populated based on other choices and (2) it's not already populated.

What I've noticed seems to be happening is that even if the date has a value, when the arcade is evaluated in Experience Builder, the value is coming back empty. This might be a bug...

Here's the arcade for the Check Out Time in the following screenshots.

var checkOutTime = $feature.CheckOut;
var attendance = $feature.Attendance;
var checkOut = $feature.CheckOutChoice; 

if(attendance=='Present' && checkOut == 'Yes'){
  if (2 == 1){
    checkOutTime = Now();
  }
}

return checkOutTime;

 

In this example, both the check in and check out time are populated. Here's how the edit form looks in the web map.

nulldate_webmap.jpg

 

And here's the same record in the edit widget in Experience Builder.  Since the check out date is coming through as null -- i'm thinking that the value isn't getting sent to the arcade expression maybe?  

nulldate_exb.jpg

 

The values are being shown as expected in the pop up displays .. 
nulldate_exb_details.jpg

 

Thanks for any ideas you might have!

Tags (2)
0 Kudos
1 Solution

Accepted Solutions
Allen_Zhang
Regular Contributor

Hi @jessneuner 

The edit widget seems like an "attribute only" mode.

I guess the "attribute only" mode does not support arcade expression currently.

I tested a "map" mode edit widget, and found the arcade fields worked.

Maybe you can try the map mode.

View solution in original post

0 Kudos
6 Replies
Allen_Zhang
Regular Contributor

Hi @jessneuner 

The edit widget seems like an "attribute only" mode.

I guess the "attribute only" mode does not support arcade expression currently.

I tested a "map" mode edit widget, and found the arcade fields worked.

Maybe you can try the map mode.

0 Kudos
jessneuner
Frequent Contributor

aaah... dang.  This is a stand alone table. hmm...

I have a different field with a calculation that is working great -- just this date field that's causing me trouble.

0 Kudos
Allen_Zhang
Regular Contributor

Try select the "Use webmap settings" in "Configure fields".

The "Customize" has some problem I just remember.

Allen_Zhang_0-1745547409658.png

 

0 Kudos
jessneuner
Frequent Contributor

Thanks @Allen_Zhang Does seem like an Attribute_only vs map thing.  Did a similar test with a feature layer instead of stand alone table this morning and saw the same behavior (just a simple pass through of the value with the arcade calculation) and they didn't pass through in attribute only mode, but did in the map side. 

 

bummer!  i have a Survery123 version of the logic that works great - the UX isn't quite as nice as the edit widget but will get the job done!

appreciate your help!

0 Kudos
ChristopherCounsell
MVP Regular Contributor
var checkOutTime = $feature.CheckOut;
var attendance = $feature.Attendance;
var checkOut = $feature.CheckOutChoice; 

if(attendance=='Present' && checkOut == 'Yes'){
  if (2 == 1){
    checkOutTime = Now();
  }
}

return checkOutTime;

if 2 = 1 means it will always return false? what's the point of this if statement?

I would recommend:

  • Looking at the edit modes. If the record is getting created on check-in you could use the 'INSERT' check to populate the time for when the record is created, and then not later on.
  • Use the $originalFeature to prevent the features from getting recalculated
  • Be conscious of preserving values hidden by question visibility (it's a form setting, by default they can get discarded)

e.g.

    var mode = $editcontext.editType;
    if (mode == "INSERT") {
        return now()
    } else {
        return $originalFeature.checkintime
    }  

and

var CheckedOut = $feature.CheckedOut;  // Checked out 'Yes'?
var OriginalCheckOutTime = $originalFeature.CheckOutTime;  // current checkout time on form load

// Check if CheckedOut is 'Yes' and CheckOut time is currently empty
if (CheckedOut == 'Yes' && IsEmpty(OriginalCheckOutTime)) {
    return Now();
} else {
    return OriginalCheckOutTime// Use $originalFeature to get the original field value which would be null or the first checkout time calculated
}

Some of syntax might not quite be right sorry just writing this off memory on the forum 😄

 

0 Kudos
jessneuner
Frequent Contributor

thanks @ChristopherCounsell !

I appreciate you taking a look -- the 2=1 came about because I was confused why it was always updating the date to Now even when it was already populated, so wanted it to skip that part and that's when I realized -- is it not even getting the date??

Thank you for the tip on edit mode also!  I wound up going down that rabbit hole last night as well -- and all the visibility stuff ... I realized that even if values are hidden those calculations are getting executed which i hadn't expected ... learning a lot!

0 Kudos