Calculations using related fields fail in app

277
1
06-11-2023 07:24 PM
tendtreesTC
New Contributor III

Hi There,

I have been building an auditing app in fieldmaps in which I have a layer for the site and a related table to undertake an audit on that site.

within the site layer I have built some calculations that work fine on existing sites however when I create a new site the fields return the error 'Failed to calculate' and won't let me submit.

I am assuming it is because there are not related records yet so it has nothing to calculate.

below is an example of one of the calculations to find the date of the last audit.

var fs = OrderBy(FeatureSetByRelationshipName($feature, 'WCC_Hort_Site_Auditing_XV2X_inspection_audit'),"CreationDate DES");
var feat = First(fs);
var result = iif(IsEmpty(feat['audit_date']),'',feat['audit_date'])
return result;
 
does anyone have a solution for this?
0 Kudos
1 Reply
DougBrowning
MVP Esteemed Contributor

If there are zero records I think this line will fail 

var feat = First(fs);

What I do is check for no records a little earlier than where you did.

Not proper syntax but like this - check the count on fs first.

if count(fs) == 0 then return '' if not then return var feat = First(fs);

I am not positive you can return '' to a date field though may need to use Null.

Hope that makes sense.

0 Kudos