<?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 reading optional field from JSON-file using Arcade in Data Pipelines Questions</title>
    <link>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539408#M99</link>
    <description>&lt;P&gt;This code will check if the Feature or FeatureSet contains a field.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function fieldExists(item, fieldName) { //item can be a Feature or FeatureSet
  var fields = Schema(item).fields;
  for (var i in fields) {
    if (Lower(fields[i].name) == Lower(fieldName)) return true;
  }
  return false;
}

iif(fieldExists($feature, "field_name"), "Field Exists", "Field doesn't exist");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 17 Sep 2024 12:45:39 GMT</pubDate>
    <dc:creator>KenBuja</dc:creator>
    <dc:date>2024-09-17T12:45:39Z</dc:date>
    <item>
      <title>Issue reading optional field from JSON-file using Arcade</title>
      <link>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539272#M98</link>
      <description>&lt;DIV&gt;I have a scheduled data pipeline that once a day reads a JSON-file and writes it to a feature service. In the pipeline, I do numerous&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;calculate field&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/I&gt;where I use Arcade to get the information I need from the JSON-file. In these scripts I use $record.&amp;nbsp;to fetch the information I need (&lt;I&gt;$record.approximateEnd&lt;/I&gt;&amp;nbsp;in the example below). The issue I am facing is that some of this information is not always present in the input file. When this happens, the arcade script throws an&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;Execution error - Key not found,&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/I&gt;and the pipeline does not run/fails (no data is updated). I would like to modify my script so that it first tests if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;$record.approximateEnd&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/I&gt;exists. If it does not exist it would create a null value. Any other solution that would prevent my pipeline from failing when data is missing would also work.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;My input data is&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;A href="https://opendata.smhi.se/apidocs/IBWwarnings/objects.html#warningareas" target="_blank" rel="noopener"&gt;SMHI Open Data API Docs - Warnings&lt;/A&gt;.&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;(I already check if&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;$record.approximateEnd&lt;/I&gt;&amp;nbsp;is null but I need something to cover the case when there is no&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;I&gt;$record.approximateEnd&lt;/I&gt;&amp;nbsp;at all.)&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// Check that EndDate exist, save as Date.

if(IsEmpty($record.approximateEnd)){
  return null;
} else {
  var MyDate = Split(Left($record.approximateEnd, 10),"-");
  var MyTime = Right($record.approximateEnd, 13);
  
  MyTime = Split(Left(MyTime, 8), ":");
  
  MyDate = Date(MyDate[0], (MyDate[1]-1), MyDate[2], MyTime[0], MyTime[1], MyTime[2]);
}

// Check that EndDate is later than StartDate

if (MyDate&amp;gt;$record.Start_) {
  return MyDate;  
} else {
  return null;
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AndreasHall_0-1726548484898.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115250i3AC208436E48B583/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AndreasHall_0-1726548484898.png" alt="AndreasHall_0-1726548484898.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="AndreasHall_1-1726548496979.png" style="width: 400px;"&gt;&lt;img src="https://community.esri.com/t5/image/serverpage/image-id/115251i88D8493342D05985/image-size/medium?v=v2&amp;amp;px=400" role="button" title="AndreasHall_1-1726548496979.png" alt="AndreasHall_1-1726548496979.png" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 04:49:49 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539272#M98</guid>
      <dc:creator>AndreasHall</dc:creator>
      <dc:date>2024-09-17T04:49:49Z</dc:date>
    </item>
    <item>
      <title>Re: Issue reading optional field from JSON-file using Arcade</title>
      <link>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539408#M99</link>
      <description>&lt;P&gt;This code will check if the Feature or FeatureSet contains a field.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;function fieldExists(item, fieldName) { //item can be a Feature or FeatureSet
  var fields = Schema(item).fields;
  for (var i in fields) {
    if (Lower(fields[i].name) == Lower(fieldName)) return true;
  }
  return false;
}

iif(fieldExists($feature, "field_name"), "Field Exists", "Field doesn't exist");&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 12:45:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539408#M99</guid>
      <dc:creator>KenBuja</dc:creator>
      <dc:date>2024-09-17T12:45:39Z</dc:date>
    </item>
    <item>
      <title>Re: Issue reading optional field from JSON-file using Arcade</title>
      <link>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539596#M101</link>
      <description>&lt;P&gt;Hi Andreas!&lt;/P&gt;&lt;P&gt;There are two relevant Arcade functions that will likely be helpful here:&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/feature_functions/#defaultvalue" target="_self"&gt;DefaultValue&lt;/A&gt;&lt;/LI&gt;&lt;LI&gt;&lt;A href="https://developers.arcgis.com/arcade/function-reference/feature_functions/#hasvalue" target="_self"&gt;HasValue&lt;/A&gt;&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;So in your example, you could use DefaultValue similarly:&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;// Set end date to null if the field does not exist. 
var endDate = DefaultValue($record, "approximateEnd", null)&lt;/LI-CODE&gt;&lt;P&gt;Hopefully these functions will give your arcade script the flexibility it needs to handle JSON with varying properties. Please let me know if you have any more questions regarding this.&lt;/P&gt;&lt;P&gt;Thank you,&lt;/P&gt;&lt;P&gt;Duncan&lt;/P&gt;</description>
      <pubDate>Tue, 17 Sep 2024 16:52:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539596#M101</guid>
      <dc:creator>DuncanMackey</dc:creator>
      <dc:date>2024-09-17T16:52:39Z</dc:date>
    </item>
    <item>
      <title>Re: Issue reading optional field from JSON-file using Arcade</title>
      <link>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539867#M102</link>
      <description>&lt;P&gt;Great, thanks a lot!&lt;/P&gt;</description>
      <pubDate>Wed, 18 Sep 2024 07:56:36 GMT</pubDate>
      <guid>https://community.esri.com/t5/data-pipelines-questions/issue-reading-optional-field-from-json-file-using/m-p/1539867#M102</guid>
      <dc:creator>AndreasHall</dc:creator>
      <dc:date>2024-09-18T07:56:36Z</dc:date>
    </item>
  </channel>
</rss>

