<?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: Adding hyperlink field, syntax error in url in Python Questions</title>
    <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227982#M66005</link>
    <description>&lt;P&gt;Thanks Johannes, exactly what I needed!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 02 Nov 2022 16:45:20 GMT</pubDate>
    <dc:creator>ErichSchreier</dc:creator>
    <dc:date>2022-11-02T16:45:20Z</dc:date>
    <item>
      <title>Adding hyperlink field, syntax error in url</title>
      <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227571#M65984</link>
      <description>&lt;P&gt;Hello!&lt;/P&gt;&lt;P&gt;I am trying to add a hyperlink field to a feature class so I can use it in a pop-up on a viewer. The issue I am having is with the url itself; I receive an invalid syntax error on the url.&amp;nbsp;&lt;/P&gt;&lt;P&gt;The feature class has a 'LINK ID' field, which is a number that sits at the end of a base url. So what I need to do is add a field for the hyperlink (I got that to work just fine), and then calculate this field by concatenating the base url string with the Link ID field. Here is the line of the code that is failing:&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;arcpy.management.CalculateField(fc, 'HYPERLINK', 'https://msc.fema.gov/portal/downloadProduct?productID='+'LINKID&amp;nbsp;', "Python 3")&lt;/P&gt;&lt;P&gt;I have tried using .format methods as well, and continue to receive invalid syntax on the url. Any help is appreciated, thank you!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 17:59:46 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227571#M65984</guid>
      <dc:creator>ErichSchreier</dc:creator>
      <dc:date>2022-11-01T17:59:46Z</dc:date>
    </item>
    <item>
      <title>Re: Adding hyperlink field, syntax error in url</title>
      <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227593#M65985</link>
      <description>&lt;P&gt;Looks like you have a space between the D and '.&amp;nbsp;&lt;/P&gt;&lt;P&gt;I take it LINKID is a number... Might try casting to string. str(LINKID)&amp;nbsp; I know you tried format, but sometimes you just need to be explicit.&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 18:19:38 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227593#M65985</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-11-01T18:19:38Z</dc:date>
    </item>
    <item>
      <title>Re: Adding hyperlink field, syntax error in url</title>
      <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227600#M65986</link>
      <description>&lt;P&gt;LinkID needs to be between exclamation points.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;arcpy.management.CalculateField(fc, 'HYPERLINK', '"&lt;A href="https://msc.fema.gov/portal/downloadProduct?productID=" target="_blank" rel="noopener"&gt;https://msc.fema.gov/portal/downloadProduct?productID=&lt;/A&gt;"+!LINKID!', "Python 3")&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 18:31:43 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227600#M65986</guid>
      <dc:creator>dgiersz_cuyahoga</dc:creator>
      <dc:date>2022-11-01T18:31:43Z</dc:date>
    </item>
    <item>
      <title>Re: Adding hyperlink field, syntax error in url</title>
      <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227603#M65987</link>
      <description>&lt;P data-unlink="true"&gt;Thanks for the response! I should have been a bit more clear, the syntax error is in the url itself. It does not like the semicolon after the https.&amp;nbsp;&lt;/P&gt;&lt;P data-unlink="true"&gt;Yep, the link id is a number that will be added on to then end of the url.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 01 Nov 2022 18:45:24 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227603#M65987</guid>
      <dc:creator>ErichSchreier</dc:creator>
      <dc:date>2022-11-01T18:45:24Z</dc:date>
    </item>
    <item>
      <title>Re: Adding hyperlink field, syntax error in url</title>
      <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227746#M65993</link>
      <description>&lt;P&gt;I did a little local test and replicated the issue.&amp;nbsp; Using the ! surrounding the field returned an eol expected error as well. Seeing that you are using this in a standalone script, I'd just use an update cursor:&lt;/P&gt;&lt;LI-CODE lang="python"&gt;    with arcpy.da.UpdateCursor(fc, ['HYPERLINK', 'LINKID']) as uCur:
        for row in uCur:
            row[0] = fr'https://msc.fema.gov/portal/downloadProduct?productID={row[1]}'
            uCur.updateRow(row)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 01:02:41 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227746#M65993</guid>
      <dc:creator>Anonymous User</dc:creator>
      <dc:date>2022-11-02T01:02:41Z</dc:date>
    </item>
    <item>
      <title>Re: Adding hyperlink field, syntax error in url</title>
      <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227796#M65996</link>
      <description>&lt;P&gt;Using Calculate Field in a Python script is a little tricky.&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;As already said, you have to enclose field names with exclamation marks.&lt;/LI&gt;&lt;LI&gt;What&amp;nbsp;&lt;a href="https://community.esri.com/t5/user/viewprofilepage/user-id/414954"&gt;@dgiersz_cuyahoga&lt;/a&gt;&amp;nbsp;did in his answer but didn't actually say: You have to supply the expression as a string. Your expression is (almost) correct when you use it in the Python window. For it to work in the tool, you have to turn it into a string. Just surround it with quotes (the type you didn't use in the expression, or triple quotes):&lt;/LI&gt;&lt;/UL&gt;&lt;LI-CODE lang="python"&gt;# this works in a Python console, assuming LINKID is a defined variable
'https://msc.fema.gov/portal/downloadProduct?productID=' + str(LINKID)
# or with newer syntax
f'https://msc.fema.gov/portal/downloadProduct?productID={LINKID}'

# for Calculate field, you have to supply the expression as string
"'https://msc.fema.gov/portal/downloadProduct?productID=' + str(!LINKID!)"
"f'https://msc.fema.gov/portal/downloadProduct?productID={!LINKID!}'"&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 07:42:39 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227796#M65996</guid>
      <dc:creator>JohannesLindner</dc:creator>
      <dc:date>2022-11-02T07:42:39Z</dc:date>
    </item>
    <item>
      <title>Re: Adding hyperlink field, syntax error in url</title>
      <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227981#M66004</link>
      <description>&lt;P&gt;Thanks Jeff! The simple syntax in Johannes' answer was a quick fix, but I will certainly be keeping the update cursor in my mind for future projects.&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 16:44:30 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227981#M66004</guid>
      <dc:creator>ErichSchreier</dc:creator>
      <dc:date>2022-11-02T16:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Adding hyperlink field, syntax error in url</title>
      <link>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227982#M66005</link>
      <description>&lt;P&gt;Thanks Johannes, exactly what I needed!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 02 Nov 2022 16:45:20 GMT</pubDate>
      <guid>https://community.esri.com/t5/python-questions/adding-hyperlink-field-syntax-error-in-url/m-p/1227982#M66005</guid>
      <dc:creator>ErichSchreier</dc:creator>
      <dc:date>2022-11-02T16:45:20Z</dc:date>
    </item>
  </channel>
</rss>

