<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Issue with an Arcade calculation expression that works correctly in Map Viewer but not in Field Maps in ArcGIS Field Maps Questions</title>
    <link>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1481361#M8751</link>
    <description>&lt;P&gt;I approached it a bit differently, but this seem to be working as you expect in both map viewer and Field Maps app.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Check if the edit type is 'INSERT'
if ($editcontext.editType == 'INSERT') {
    
    // Access the FeatureSet of the relevant layer with required fields
    var fs = FeatureSetByName($map, 'מדידת שריפה', ['FireEditStatus', 'FireGisID', 'created_user'], false);
    
    // Get the current user's username from the FeatureSet
    var username = GetUser(FeatureSetByName($map, 'מדידת שריפה')).username

    var uservals = ''

    if (!IsEmpty(fs)){                                                      //make sure not empty dataset 
        if ($feature.FireEditStatus == 2){
            var uservals = Filter(fs, `created_user = '${username}'`)      // If Continuing Fire, filter data by username
        }else{
            var uservals = fs                                             // else grab all data
            }
        
        var numarray = []
        for (var n in uservals){
            Push(numarray, n.fireGisID)                      // push all matching IDs to array
        }
        var newID = Max(numarray)                           // get the max ID number 
        if ($feature.FireEditStatus == 2){
            return newID                                   // If status = 2, return Max existing ID
        }else{
            return newID + 1                              // otherwise, return max ID incremented by 1
        }
    }
} else {
    return $feature.FireGisID;                         // For other edit types, return the existing FireGisID
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Thu, 30 May 2024 17:18:19 GMT</pubDate>
    <dc:creator>RhettZufelt</dc:creator>
    <dc:date>2024-05-30T17:18:19Z</dc:date>
    <item>
      <title>Issue with an Arcade calculation expression that works correctly in Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1478900#M8724</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;&lt;P&gt;I'm encountering an issue with a calculation expression that works correctly in Map Viewer but not in Field Maps. I have an expression that computes a fire incident number automatically based on the fire's status. When the fire status is 1 (new fire), the calculation finds the maximum number in the layer and adds one. When the fire status is 2 (continuing fire), the calculation finds the last fire number for the same user.&lt;/P&gt;&lt;P&gt;In Map Viewer, the calculation works perfectly. However, in Field Maps, I'm experiencing two issues:&lt;/P&gt;&lt;P&gt;For status 1, I get a number smaller than the maximum number.&lt;BR /&gt;For status 2, I get 0 instead of the expected number.&lt;BR /&gt;Here's the expression I'm using:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Check if the edit type is 'INSERT'
if ($editcontext.editType == 'INSERT') {
    // Access the FeatureSet of the relevant layer with required fields
    var fs = FeatureSetByName($map, 'מדידת שריפה', ['FireEditStatus', 'FireGisID', 'created_user'], false);
    
    // Get the current user's username
    var username = GetUser($layer).username;

    // Initialize variables
    var MaxidStatus1 = 0;
    var MaxidStatus2 = 0;
    var hasStatus2 = false;

    // Iterate through the features in the FeatureSet
    for (var f in fs) {
        var fireEditStatus = f['FireEditStatus'];
        var fireGisID = Number(f['FireGisID']);
        
        // Check if the FireEditStatus is 1 and update the maximum FireGisID
        if (fireEditStatus == 1) {
            MaxidStatus1 = Max(MaxidStatus1, fireGisID);
        }
        
        // Check if the FireEditStatus is 2 and the created_user matches the current user
        if (fireEditStatus == 2 &amp;amp;&amp;amp; f['created_user'] == username) {
            hasStatus2 = true;
            MaxidStatus2 = Max(MaxidStatus2, fireGisID);
        }
    }
    
    // Determine the new FireGisID based on FireEditStatus
    if ($feature.FireEditStatus == 2) {
        // If FireEditStatus is 2, return the maximum FireGisID for the current user
        if (hasStatus2) {
            return MaxidStatus2;
        } else {
            return null;
        }
    } else if ($feature.FireEditStatus == 1) {
        // Increment the maximum FireGisID by 1 for status 1
        return MaxidStatus1 + 1;
    } else {
        return null;
    }
} else {
    // For other edit types, return the existing FireGisID
    return $feature.FireGisID;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Has anyone experienced similar issues with expressions in Field Maps, and what solutions might you suggest?&lt;/P&gt;&lt;P&gt;Thank you for your assistance!&lt;/P&gt;&lt;P&gt;Guy&lt;/P&gt;</description>
      <pubDate>Mon, 27 May 2024 05:28:01 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1478900#M8724</guid>
      <dc:creator>GuyNizry</dc:creator>
      <dc:date>2024-05-27T05:28:01Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with an Arcade calculation expression that works correctly in Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1479727#M8730</link>
      <description>&lt;P&gt;It appears as if Getuser has some issues with Field maps app and could be your issue.&lt;/P&gt;&lt;P&gt;&lt;A href="https://community.esri.com/t5/arcgis-field-maps-questions/quot-failed-to-calculate-quot-error-on-getuser/m-p/1356023#M7482" target="_self"&gt;Take a look here and see if this help&lt;/A&gt;s.&amp;nbsp; More &lt;A href="https://community.esri.com/t5/arcgis-field-maps-questions/field-maps-getuser-not-working-in-mobile-app/td-p/1356484" target="_self"&gt;here&lt;/A&gt;.&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;</description>
      <pubDate>Tue, 28 May 2024 18:56:11 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1479727#M8730</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-05-28T18:56:11Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with an Arcade calculation expression that works correctly in Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1479968#M8734</link>
      <description>&lt;P&gt;Thank you, &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;&amp;nbsp;, for the suggestion and the links.&lt;/P&gt;&lt;P&gt;I tried using GetUser as suggested in the post you linked, but the fire incident number still returns 0 in Field Maps instead of the maximum number for that user.&lt;/P&gt;&lt;P&gt;In Map Viewer, the correct number is returned. Do you have any additional ideas for solving this issue?&lt;/P&gt;&lt;P&gt;Here is the updated expression:&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Check if the edit type is 'INSERT'
if ($editcontext.editType == 'INSERT') {
    // Access the FeatureSet of the relevant layer with required fields
    var fs = FeatureSetByName($map, 'מדידת שריפה', ['FireEditStatus', 'FireGisID', 'created_user'], false);
    
    // Get the current user's username from the portal
    var userInfo = GetUser(portal("https://www.arcgis.com"), "");
    var username = userInfo.userName;
    
    // Initialize variables
    var MaxidStatus1 = 0;
    var MaxidForUser = 0;

    // Iterate through the features in the FeatureSet
    for (var f in fs) {
        var fireEditStatus = f['FireEditStatus'];
        var fireGisID = Number(f['FireGisID']);
        
        // Check if the FireEditStatus is 1 and update the maximum FireGisID
        if (fireEditStatus == 1) {
            MaxidStatus1 = Max(MaxidStatus1, fireGisID);
        }
        
        // Check if the created_user matches the current user and update the maximum FireGisID for the user
        if (f['created_user'] == username) {
            MaxidForUser = Max(MaxidForUser, fireGisID);
        }
    }
    
    // Determine the new FireGisID based on FireEditStatus
    if ($feature.FireEditStatus == 2) {
        // If FireEditStatus is 2, return the maximum FireGisID for the current user
        return MaxidForUser;
    } else if ($feature.FireEditStatus == 1) {
        // Increment the maximum FireGisID by 1 for status 1
        return MaxidStatus1 + 1;
    } else {
        return null;
    }
} else {
    // For other edit types, return the existing FireGisID
    return $feature.FireGisID;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 29 May 2024 05:48:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1479968#M8734</guid>
      <dc:creator>GuyNizry</dc:creator>
      <dc:date>2024-05-29T05:48:22Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with an Arcade calculation expression that works correctly in Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1481361#M8751</link>
      <description>&lt;P&gt;I approached it a bit differently, but this seem to be working as you expect in both map viewer and Field Maps app.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Check if the edit type is 'INSERT'
if ($editcontext.editType == 'INSERT') {
    
    // Access the FeatureSet of the relevant layer with required fields
    var fs = FeatureSetByName($map, 'מדידת שריפה', ['FireEditStatus', 'FireGisID', 'created_user'], false);
    
    // Get the current user's username from the FeatureSet
    var username = GetUser(FeatureSetByName($map, 'מדידת שריפה')).username

    var uservals = ''

    if (!IsEmpty(fs)){                                                      //make sure not empty dataset 
        if ($feature.FireEditStatus == 2){
            var uservals = Filter(fs, `created_user = '${username}'`)      // If Continuing Fire, filter data by username
        }else{
            var uservals = fs                                             // else grab all data
            }
        
        var numarray = []
        for (var n in uservals){
            Push(numarray, n.fireGisID)                      // push all matching IDs to array
        }
        var newID = Max(numarray)                           // get the max ID number 
        if ($feature.FireEditStatus == 2){
            return newID                                   // If status = 2, return Max existing ID
        }else{
            return newID + 1                              // otherwise, return max ID incremented by 1
        }
    }
} else {
    return $feature.FireGisID;                         // For other edit types, return the existing FireGisID
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R_&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 30 May 2024 17:18:19 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1481361#M8751</guid>
      <dc:creator>RhettZufelt</dc:creator>
      <dc:date>2024-05-30T17:18:19Z</dc:date>
    </item>
    <item>
      <title>Re: Issue with an Arcade calculation expression that works correctly in Map Viewer but not in Field Maps</title>
      <link>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1481810#M8762</link>
      <description>&lt;P&gt;Thank you so much for your help, &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/15530"&gt;@RhettZufelt&lt;/a&gt;. The approach you provided indeed resolves the issue, and the calculations are now working correctly in both Map Viewer and the Field Maps app.&lt;/P&gt;&lt;P&gt;I really appreciate your assistance in solving this problem. Your support has been invaluable.&lt;/P&gt;&lt;P&gt;Guy&lt;/P&gt;</description>
      <pubDate>Fri, 31 May 2024 06:22:47 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-field-maps-questions/issue-with-an-arcade-calculation-expression-that/m-p/1481810#M8762</guid>
      <dc:creator>GuyNizry</dc:creator>
      <dc:date>2024-05-31T06:22:47Z</dc:date>
    </item>
  </channel>
</rss>

