<?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: Editor.js:426 Uncaught TypeError: Cannot read properties of undefined (reading 'layer') in ArcGIS JavaScript Maps SDK Questions</title>
    <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214228#M78766</link>
    <description>&lt;P&gt;I'm not sure that I'm following.&amp;nbsp; Isn't the "if (layer.title ==="xxx), etc." the layer definition?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 20 Sep 2022 15:32:03 GMT</pubDate>
    <dc:creator>WilliamShuart</dc:creator>
    <dc:date>2022-09-20T15:32:03Z</dc:date>
    <item>
      <title>Editor.js:426 Uncaught TypeError: Cannot read properties of undefined (reading 'layer')</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214037#M78753</link>
      <description>&lt;P&gt;I have an editing app and I am getting a type error thrown.&amp;nbsp; I have layers defined and pointing to a hosted serviuce/map.&lt;/P&gt;&lt;P&gt;Editor.js:426 Uncaught TypeError: Cannot read properties of undefined (reading 'layer')&lt;/P&gt;&lt;P&gt;at Editor.js:426:139&lt;BR /&gt;at Array.find (&amp;lt;anonymous&amp;gt;)&lt;BR /&gt;at J (Editor.js:426:129)&lt;BR /&gt;at Editor.js:441:414&lt;BR /&gt;at Array.map (&amp;lt;anonymous&amp;gt;)&lt;BR /&gt;at F.map ((index):64:265)&lt;BR /&gt;at v.get (Editor.js:441:335)&lt;BR /&gt;at Object.u [as runTracked] ((index):160:183)&lt;BR /&gt;at t.getComputed ((index):154:279)&lt;BR /&gt;at p.get ((index):146:326)&lt;BR /&gt;(anonymous) @ Editor.js:426&lt;BR /&gt;J @ Editor.js:426&lt;BR /&gt;(anonymous) @ Editor.js:441&lt;BR /&gt;F.map @ (index):64&lt;BR /&gt;get @ Editor.js:441&lt;BR /&gt;u @ (index):160&lt;BR /&gt;t.getComputed @ (index):154&lt;BR /&gt;p.get @ (index):146&lt;BR /&gt;c @ (index):135&lt;BR /&gt;d @ (index):135&lt;BR /&gt;(anonymous) @ (index):171&lt;BR /&gt;u @ (index):160&lt;BR /&gt;t @ (index):205&lt;BR /&gt;r @ (index):170&lt;BR /&gt;q @ (index):170&lt;BR /&gt;n @ (index):178&lt;BR /&gt;(anonymous) @ (index):182&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;&amp;lt;html&amp;gt;
  &amp;lt;head&amp;gt;
    &amp;lt;meta charset="utf-8" /&amp;gt;
    &amp;lt;meta
      name="viewport"
      content="initial-scale=1,maximum-scale=1,user-scalable=no"
    /&amp;gt;
    &amp;lt;title&amp;gt;
      Area of roof Calculation based on Slope
    &amp;lt;/title&amp;gt;

    &amp;lt;link
      rel="stylesheet"
      href="https://js.arcgis.com/4.23/esri/themes/light/main.css"
    /&amp;gt;
    &amp;lt;script src="https://js.arcgis.com/4.23/"&amp;gt;&amp;lt;/script&amp;gt;

    &amp;lt;style&amp;gt;
      html,
      body,
      #viewDiv {
        padding: 0;
        margin: 0;
        height: 100%;
        width: 100%;
      }

      .esri-editor .esri-item-list__scroller {
        max-height: 350px;
      }
    &amp;lt;/style&amp;gt;

    &amp;lt;script&amp;gt;
            require(["esri/WebMap", "esri/views/MapView", "esri/popup/ExpressionInfo", "esri/widgets/Editor", "esri/widgets/Search", "esri/layers/FeatureLayer"], (
              WebMap,
              MapView,
              ExpressionInfo,
              Editor,
              Search,
              FeatureLayer
              
            ) =&amp;gt; {

              let EntireStructureLayer, DamagedAreasLayer;

              // Create a map from the referenced webmap item id
              const webmap = new WebMap({
                portalItem: {
                  id: "6a98a932b16142ae9d262e3e48a021a3"
                }
              });

              const view = new MapView({
                container: "viewDiv",
                map: webmap
              });
              
              const featureLayerROE = new FeatureLayer({
                url: "https://services.arcgis.com/9MNW08Jq46DD7XQg/arcgis/rest/services/brms_09122022_WFL1/FeatureServer/5",
                popuptemplate: {
                  title: "ROE Number {roeidpk}",
                  overwriteActions: true
                }
			  });

              view.when(() =&amp;gt; {
                view.map.layers.forEach((layer) =&amp;gt; {
                  if (layer.title === "Entire Structure") {
					EntireStructureLayer = {
                    layer: EntireStructure,
                    formTemplate: {
                      // autocasts to FormTemplate
                      elements: [
                        {
                          type: "field",
                          fieldName: "ROE_IDPK",
                          label: "ROE Number"
                        },
                        {
                          // autocasts to FieldElement
                          type: "field",
                          fieldName: "Area_SQFT",
                          label: "Area in Square Feet",
                           // expression defined in expressionInfos
                           valueExpression: "area"
                        },
                        {
                          type: "field",
                          fieldName: "Pitch_Slope",
                          label: "Pitch of Roof"                         
                        },
                        {
                          type: "field",
                          fieldName: "Area_pitch_SQFT",
                          label: "Area based on Pitch (FT)",
                          // expression defined in expressionInfos
                          valueExpression: "Pitchft2",
                        },
                        {
                          type: "field",
                          fieldname: "RoofType",
                          label: "Type of Roof"
                        },
                      ],

                     expressionInfos: [{
                     name: "area",
                     title: "Area SQ FT",
                     expression: "AreaGeodetic($feature,'feet')"
                     }, {
                     name: "Pitchft2",
                     title: "Area based on Pitch (FT)",
                     expression:' "$feature.Pitch_Slope==1, $feature.Area_SQFT*1.031, $feature.Pitch_Slope==2, $feature.Area_SQFT*1.158, $feature.Pitch_Slope==3, $feature.Area_SQFT*1.414, $feature.Pitch_Slope==4, $feature.Area_SQFT*1.944, $feature.Area_SQFT)"'     
                   }
				 ]
               }
             };
			 } else {
				if(layer.title === "DamagedAreasmultipatch") 
                  DamagedAreasLayer = {
                    layer: DamagedAreasmultipatch,
                    formTemplate: {
                      // autocasts to FormTemplate
                      elements: [
                        {
                          type: "field",
                          fieldName: "ROE_IDPK",
                          label: "ROE Number"
                        },
                        {
                          // autocasts to FieldElement
                          type: "field",
                          fieldName: "Area_Ft2",
                          label: "Area in Square Feet",
                           // expression defined in expressionInfos
                           valueExpression: "area1"
                        },
                        {
                          type: "field",
                          fieldName: "Pitch",
                          label: "Pitch of Roof"                         
                        },
                        {
                          type: "field",
                          fieldName: "Area_pitch_ft2",
                          label: "Area based on Pitch (FT)",
                          // expression defined in expressionInfos
                          valueExpression: "Pitchft2"
                        },
                        {
                          type: "field",
                          fieldName: "NumPanels",
                          label: "Number of Plywood Panels Needed"
                        },
                        {
                          type: "field",
                          fieldName: "Length_rafters_area",
                          label: "Length of Rafters Needed"
                        }
                      ],

                     expressionInfos: [{
                     name: "area1",
                     title: "Area SQ FT",
                     expression: "AreaGeodetic($feature,'feet')"
                     }, {
                     name: "Pitchft2",
                     title: "Area based on Pitch (FT)",
                     expression:' "$feature.Pitch==1, $feature.Area_Ft2*1.031, $feature.Pitch==2, $feature.Area_Ft2*1.158, $feature.Pitch==3, $feature.Area_Ft2*1.414, $feature.Pitch==4, $feature.Area_Ft2*1.944, $feature.Area_Ft2)"'
                   }
				   ]
                 }
               };
			 }
			});
			const searchWidget = new Search({
			view: view,
			allPlaceholder: "Search",
			includeDefaultSources: false,
			sources: [
            {
              layer: featureLayerROE,
              searchFields: ["roeidpk"],
              displayField: "ROE IDPK",
              exactMatch: true,
              outFields: ["roeidpk", "flagroe", "invoicenumber"],
              name: "ROE IDPK",
              placeholder: "example: 278585"
            }
            ]
            });		  
            const editor = new Editor({
			layerInfos: [EntireStructureLayer, DamagedAreasLayer],  
			view: view,			 
          });
                  // Add the widget to the view
                  view.ui.add(editor, "top-right");
                  view.ui.add(searchWidget, "bottom-right")
              });
            });
    &amp;lt;/script&amp;gt;
  &amp;lt;/head&amp;gt;
&amp;lt;body&amp;gt;
  &amp;lt;div id="viewDiv"&amp;gt;&amp;lt;/div&amp;gt;
&amp;lt;/body&amp;gt;

&amp;lt;/html&amp;gt;&lt;/LI-CODE&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 00:35:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214037#M78753</guid>
      <dc:creator>WilliamShuart</dc:creator>
      <dc:date>2022-09-20T00:35:39Z</dc:date>
    </item>
    <item>
      <title>Re: Editor.js:426 Uncaught TypeError: Cannot read properties of undefined (reading 'layer')</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214212#M78764</link>
      <description>&lt;P&gt;You have a couple of spots where you're passing a layer, but it's not defined.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (layer.title === "Entire Structure") {
    EntireStructureLayer = {
    layer: EntireStructure, // EntireStructure undefined

if(layer.title === "DamagedAreasmultipatch") // missing {} too
DamagedAreasLayer = {
    layer: DamagedAreasmultipatch, // DamagedAreasmultipatch undefined&lt;/LI-CODE&gt;&lt;P&gt;In those cases, if the title matches, you can just pass the layer instance for the editor to use.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 15:01:29 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214212#M78764</guid>
      <dc:creator>ReneRubalcava</dc:creator>
      <dc:date>2022-09-20T15:01:29Z</dc:date>
    </item>
    <item>
      <title>Re: Editor.js:426 Uncaught TypeError: Cannot read properties of undefined (reading 'layer')</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214228#M78766</link>
      <description>&lt;P&gt;I'm not sure that I'm following.&amp;nbsp; Isn't the "if (layer.title ==="xxx), etc." the layer definition?&amp;nbsp;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 15:32:03 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214228#M78766</guid>
      <dc:creator>WilliamShuart</dc:creator>
      <dc:date>2022-09-20T15:32:03Z</dc:date>
    </item>
    <item>
      <title>Re: Editor.js:426 Uncaught TypeError: Cannot read properties of undefined (reading 'layer')</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214231#M78767</link>
      <description>&lt;P&gt;The error is being thrown because you are not finding the right layers from your web map.&lt;/P&gt;&lt;P&gt;First of all, the layers you are looking for are in a group layer:&amp;nbsp;&lt;A href="https://www.arcgis.com/sharing/rest/content/items/6a98a932b16142ae9d262e3e48a021a3/data?f=json" target="_blank"&gt;https://www.arcgis.com/sharing/rest/content/items/6a98a932b16142ae9d262e3e48a021a3/data?f=json&lt;/A&gt;&lt;BR /&gt;&lt;BR /&gt;So you need to loop through the layers in your group layer to find the right layers:&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt; webmap.layers.forEach((layer) =&amp;gt; {
   console.log(layer.title, layer.type);
   if (layer.type === "group") {
     layer.layers.forEach((subLayer) =&amp;gt; {
       console.log(subLayer.title);
       if (subLayer.title === "Entire Structure") {
         EntireStructureLayer = {
           layer: subLayer,
         }
       }
     });
    }
});&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Secondly, you are doing the following where EntireStructure does not exist. You must set this to a valid layer instance. See the code above.&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if (layer.title === "Entire Structure") {
  EntireStructureLayer = {
    layer: EntireStructure,
  }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Lastly, DamageAreasmultipatch does not exist. Please take a look at your web map from the link provided above.&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="javascript"&gt;if(layer.title === "DamagedAreasmultipatch") &lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This codepen shows how Editor can be set up:&amp;nbsp;&lt;A href="https://codepen.io/U_B_U/pen/bGMRvmr?editors=1000" target="_blank"&gt;https://codepen.io/U_B_U/pen/bGMRvmr?editors=1000&lt;/A&gt;&lt;/P&gt;&lt;P&gt;The search widget is also throwing an error about Display field and the codepen shows the working version.&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 15:35:23 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214231#M78767</guid>
      <dc:creator>UndralBatsukh</dc:creator>
      <dc:date>2022-09-20T15:35:23Z</dc:date>
    </item>
    <item>
      <title>Re: Editor.js:426 Uncaught TypeError: Cannot read properties of undefined (reading 'layer')</title>
      <link>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214237#M78768</link>
      <description>&lt;P&gt;I got it., I see what you are saying now.&amp;nbsp; The expressions are commented out, i *thought* those were right, looks like those aren't either.&amp;nbsp; &lt;span class="lia-unicode-emoji" title=":slightly_smiling_face:"&gt;🙂&lt;/span&gt;&amp;nbsp; I am seeing errors on this pen for 'name' and 'length'.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 20 Sep 2022 19:16:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/arcgis-javascript-maps-sdk-questions/editor-js-426-uncaught-typeerror-cannot-read/m-p/1214237#M78768</guid>
      <dc:creator>WilliamShuart</dc:creator>
      <dc:date>2022-09-20T19:16:05Z</dc:date>
    </item>
  </channel>
</rss>

