<?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 ERROR 000358: Invalid expression on MakeFeatureLayer in Script Tool but no error in its Python code in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1410199#M70323</link>
    <description>&lt;P&gt;I have a Script Tool set up and its Python code executes properly when I run it outside of ArcGIS Pro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I execute the script tool that the same code is connected to in ArcGIS Pro, it fails in this way:&lt;/P&gt;&lt;PRE&gt;First condo ARN value is 410822000220226&lt;/PRE&gt;&lt;PRE&gt;Exception encountered&lt;/PRE&gt;&lt;PRE&gt;ERROR 000358: Invalid expression
Failed to execute (MakeFeatureLayer).&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The code leading up to this point is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def condo_script_tool(cntNewCondos, txtARN, subType, ws):
    arcpy.AddMessage("First condo ARN value is " + txtARN)
    arcpy.env.overwriteOutput = True
    env.workspace = ws
    proc_FC = arcpy.CreateFeatureclass_management("in_memory", "condo_proc", "POLYGON", "bc_dev.GIS_ADMIN.parcels")

    target_FC = "parcels"

    # Put in error trapping in case an error occurs when running tool
    try:
        # Make a layer from the feature class with only the parcel that has the desired ARN
        arcpy.MakeFeatureLayer_management(target_FC, "condos_lyr"," \"ROLLNUM15\" = \'" + txtARN + "\' AND SUBTYPE = "+ str(subType))
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I ask help please on why this code succeeds outside of Pro but fails inside of it. Could the target_FC maybe be the cause of the problem? How can I make it not be?&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Justin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 16 Apr 2024 13:30:08 GMT</pubDate>
    <dc:creator>JustinKraemer</dc:creator>
    <dc:date>2024-04-16T13:30:08Z</dc:date>
    <item>
      <title>ERROR 000358: Invalid expression on MakeFeatureLayer in Script Tool but no error in its Python code</title>
      <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1410199#M70323</link>
      <description>&lt;P&gt;I have a Script Tool set up and its Python code executes properly when I run it outside of ArcGIS Pro.&amp;nbsp;&lt;/P&gt;&lt;P&gt;But when I execute the script tool that the same code is connected to in ArcGIS Pro, it fails in this way:&lt;/P&gt;&lt;PRE&gt;First condo ARN value is 410822000220226&lt;/PRE&gt;&lt;PRE&gt;Exception encountered&lt;/PRE&gt;&lt;PRE&gt;ERROR 000358: Invalid expression
Failed to execute (MakeFeatureLayer).&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;The code leading up to this point is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;def condo_script_tool(cntNewCondos, txtARN, subType, ws):
    arcpy.AddMessage("First condo ARN value is " + txtARN)
    arcpy.env.overwriteOutput = True
    env.workspace = ws
    proc_FC = arcpy.CreateFeatureclass_management("in_memory", "condo_proc", "POLYGON", "bc_dev.GIS_ADMIN.parcels")

    target_FC = "parcels"

    # Put in error trapping in case an error occurs when running tool
    try:
        # Make a layer from the feature class with only the parcel that has the desired ARN
        arcpy.MakeFeatureLayer_management(target_FC, "condos_lyr"," \"ROLLNUM15\" = \'" + txtARN + "\' AND SUBTYPE = "+ str(subType))
...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Now I ask help please on why this code succeeds outside of Pro but fails inside of it. Could the target_FC maybe be the cause of the problem? How can I make it not be?&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Justin&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 13:30:08 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1410199#M70323</guid>
      <dc:creator>JustinKraemer</dc:creator>
      <dc:date>2024-04-16T13:30:08Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000358: Invalid expression on MakeFeatureLayer in Script Tool but no error in its Python code</title>
      <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1410264#M70329</link>
      <description>&lt;P&gt;I think maybe you are missing single quotes around the last part of the SQL expression for&amp;nbsp;subType. Is it a string or a number value? Try using f-string to build the expression.&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;f&lt;/SPAN&gt;&lt;SPAN&gt;"ROLLNUM15 = '&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;txtARN&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;' and SUBTYPE = '&lt;/SPAN&gt;&lt;SPAN&gt;{&lt;/SPAN&gt;&lt;SPAN&gt;subType&lt;/SPAN&gt;&lt;SPAN&gt;}&lt;/SPAN&gt;&lt;SPAN&gt;'"&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Tue, 16 Apr 2024 14:47:22 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1410264#M70329</guid>
      <dc:creator>BlakeTerhune</dc:creator>
      <dc:date>2024-04-16T14:47:22Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000358: Invalid expression on MakeFeatureLayer in Script Tool but no error in its Python code</title>
      <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1410317#M70330</link>
      <description>&lt;P&gt;Thank you &lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/191789"&gt;@BlakeTerhune&lt;/a&gt;&amp;nbsp;for the suggestion, however it did not change anything.&lt;/P&gt;&lt;P&gt;The Subtype field is a number value. Whether I include the single quotes or not makes no difference.&lt;/P&gt;&lt;P&gt;I expect it's more correct to leave them out given it's not a string data type and "where" clauses later in the script using that field succeed with no single quotes around it.&lt;BR /&gt;&lt;BR /&gt;What other details might I provide, please, to help find a solution?&lt;/P&gt;</description>
      <pubDate>Tue, 16 Apr 2024 15:49:05 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1410317#M70330</guid>
      <dc:creator>JustinKraemer</dc:creator>
      <dc:date>2024-04-16T15:49:05Z</dc:date>
    </item>
    <item>
      <title>Re: ERROR 000358: Invalid expression on MakeFeatureLayer in Script Tool but no error in its Python code</title>
      <link>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1593620#M73888</link>
      <description>&lt;P&gt;Strangely enough, on 3.2 the code runs fine on notebook but fails on nighly script with the same invalid expression error. I mean the expression is correct so seems like a bug. Did you contact ESRI about it?&lt;/P&gt;</description>
      <pubDate>Sat, 08 Mar 2025 15:30:53 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/error-000358-invalid-expression-on/m-p/1593620#M73888</guid>
      <dc:creator>Bharat</dc:creator>
      <dc:date>2025-03-08T15:30:53Z</dc:date>
    </item>
  </channel>
</rss>

