{"id":115,"date":"2010-11-04T19:37:01","date_gmt":"2010-11-04T18:37:01","guid":{"rendered":"http:\/\/www.stuartroberts.net\/?p=115"},"modified":"2010-11-04T19:37:01","modified_gmt":"2010-11-04T18:37:01","slug":"update-url-field-workflow-extendedproperties","status":"publish","type":"post","link":"http:\/\/www.stuartroberts.net\/index.php\/2010\/11\/04\/update-url-field-workflow-extendedproperties\/","title":{"rendered":"Updating URL field for ExtendedProperties in workflow"},"content":{"rendered":"<p>I was trying to update a URL field of a task within a custom workflow I was writing and spent a bit more time than I&#8217;d have liked trying to get the URL and description to save correctly in the task item being created as part of the CreateTaskWithContentType activity.<\/p>\n<p>Obviously you can&#8217;t save a SPFieldUrlValue as an object directly against the ExtendedProperties as it is not a simple type, such as a string or an integer.  Nearly every other field provided with SharePoint that contains multiple values is separated by the <em>#;<\/em> characters.  The URL field is different in that it uses the comma as the separator.  I knew this and set the extended property to something like:<\/p>\n<pre lang=\"csharp\">\r\nTaskProperties.ExtendedProperties[guidIdOfField] = \"http:\/\/somewebaddress,Description\";\r\n<\/pre>\n<p><!--more--><br \/>\nWhen the task was created the field displayed <em>http:\/\/somewebaddress,Description<\/em> and not <em>Description<\/em> as I wanted.<\/p>\n<p>It turns out that I forgot to separate using a comma and a space like:<\/p>\n<pre lang=\"csharp\">\r\nTaskProperties.ExtendedProperties[guidIdOfField] = \"http:\/\/somewebaddress, Description\";\r\n<\/pre>\n<p>This gave me the desired result of <em>Description<\/em> as the display text for the field.<\/p>\n<p>A better solution and one that shouldn&#8217;t break if Microsoft ever decide to change how URL fields store their data, is to use the SPFieldUrlValue object to set the property value, as demonstrated below:<\/p>\n<pre lang=\"csharp\">\r\nSPFieldUrlValue urlValue = new SPFieldUrlValue();\r\nurlValue.Url = \"http:\/\/someurl.com\";\r\nurlValue.Description = \"URL Description\";\r\n\r\ncreateTaskWithContentType.TaskProperties.ExtendedProperties[guidIdOfField] = urlValue.ToString();\r\n<\/pre>\n<p>This ensures that the URL is formatted to exactly how SharePoint internally expects it.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was trying to update a URL field of a task within a custom workflow I was writing and spent a bit more time than I&#8217;d have liked trying to get the URL and description to save correctly in the &hellip; <a href=\"http:\/\/www.stuartroberts.net\/index.php\/2010\/11\/04\/update-url-field-workflow-extendedproperties\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"jetpack_post_was_ever_published":false,"jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[3,82],"tags":[81,6],"jetpack_publicize_connections":[],"aioseo_notices":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/plx2I-1R","_links":{"self":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/115"}],"collection":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/comments?post=115"}],"version-history":[{"count":6,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/115\/revisions"}],"predecessor-version":[{"id":122,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/posts\/115\/revisions\/122"}],"wp:attachment":[{"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/media?parent=115"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/categories?post=115"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.stuartroberts.net\/index.php\/wp-json\/wp\/v2\/tags?post=115"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}