{"id":966,"date":"2010-09-05T06:36:51","date_gmt":"2010-09-05T06:36:51","guid":{"rendered":"https:\/\/www.wapshere.com\/missmiis\/?p=966"},"modified":"2012-08-11T00:59:28","modified_gmt":"2012-08-11T00:59:28","slug":"generate-unique-attribute-activity","status":"publish","type":"post","link":"https:\/\/www.wapshere.com\/missmiis\/generate-unique-attribute-activity","title":{"rendered":"Generate Unique Attribute Activity"},"content":{"rendered":"<p>When I first started out with MIIS <a href=\"https:\/\/www.wapshere.com\/missmiis\/what-do-you-mean-i-have-to-write-code\">I found the coding heavy going<\/a> &#8211; but soon realised that the same few extension-writing methods are used for pretty much everything, and the fun bit was just how much I could achieve with them!<\/p>\n<p>Now on to FIM and I have struggled every bit as much with learning how to write workflow activities, not particularly helped by the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ee623726.aspx\">official documentation<\/a> which I can only assume is computer generated, it is so completely unhelpful. But after a <a href=\"https:\/\/www.wapshere.com\/missmiis\/the-fim-2010-custom-logging-activity-in-vb-net\">recent<\/a> <a href=\"https:\/\/www.wapshere.com\/missmiis\/how-to-use-the-fim-readresourceactivity-in-vb-net\">obsessive<\/a> <a href=\"https:\/\/www.wapshere.com\/missmiis\/powershell-activity\">spate<\/a> I&#8217;m finally starting to get the hang of it, and this has brought me to the next fantasy activity on my list &#8211; something to generate a unique attribute, such as an AccountName.<br \/>\n<!--more--><\/p>\n<blockquote><p><strong>10th May 2011:<\/strong> I have just uploaded a new version of the activity. It has some more error checking and extra options for character-replacement and regular expression pattern matching. You will find the Download link further down this page.<\/p>\n<p><strong>11th August 2012:<\/strong> Just want the dll? A version compiled for FIM R2 is here\u00c2\u00a0<strong>with NO WARRANTY and NO SUPPORT<\/strong>: <a href=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2012\/08\/FIM.CustomWorkflowsActivityLibrary.zip\">https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2012\/08\/FIM.CustomWorkflowsActivityLibrary.zip<\/a>. AIC config details are below in this post.<\/p><\/blockquote>\n<h3>The idea<\/h3>\n<p>What I want is a way to generate an attibute based on a series of rules. If I don&#8217;t get a unique value with the first (ideal) rule, then I move to the second, then the third, then if completely desperate the fourth&#8230; Hopefully I&#8217;d have found something good by then.<\/p>\n<p>In an effort to reduce effort (if you can have that) this activity relies on the OOB Function activity to generate the possible strings in order of preference. So here&#8217;s what the workflow looks like configured with three possible choices:<\/p>\n<p><a href=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2010\/09\/GenUnique.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-2075\" title=\"GenUnique\" src=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2010\/09\/GenUnique.jpg\" alt=\"\" width=\"724\" height=\"444\" srcset=\"https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2010\/09\/GenUnique.jpg 724w, https:\/\/www.wapshere.com\/missmiis\/wp-content\/uploads\/2010\/09\/GenUnique-300x183.jpg 300w\" sizes=\"auto, (max-width: 724px) 100vw, 724px\" \/><\/a><\/p>\n<p>And here is one of the Function activties, which generates a string and puts it in a WorkflowData parameter (note I updated the pic above and now the functions below say &#8220;AccountName Option 1&#8221; instead of just &#8220;Option 1&#8221; &#8211; but they&#8217;re doing the same thing):<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/www.wapshere.com\/images\/customwf\/gua_workflowdata.JPG\" alt=\"\" \/><\/p>\n<h3>Developing the Activity<\/h3>\n<table>\n<tbody>\n<tr>\n<td>This activity is complicated compared to <a href=\"https:\/\/www.wapshere.com\/missmiis\/powershell-activity\">my powershell one<\/a>, so I&#8217;ll just summarise the steps.<\/p>\n<ol>\n<li>A CurrentRequestActivity grabs the workflow details from FIM,<\/li>\n<li>A ReadTargetActivity gets the details of the object we&#8217;re trying to modify,<\/li>\n<li>A WHILE loop goes through the possible options until a unique value is found (or we run out of options),<\/li>\n<li>Within the WHILE loop, the EnumerateResourcesActivity does the actual looking up of the proposed attribute value, to see if it&#8217;s already taken,<\/li>\n<li>We then have an IfElse statement to handle the lookup results:\n<ul>\n<li>If we found a good match we write it to the target resource using an UpdateResourceActivity,<\/li>\n<li>If we didn&#8217;t find a match an error is thrown &#8211; this leads to a PostProcessingError in FIM. Of course you could do something else like send an email here.<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<p>As well there are a bunch of code activities which smooth the way, setting up parameters and passing variables around.<\/td>\n<td><img decoding=\"async\" src=\"https:\/\/www.wapshere.com\/images\/customwf\/gua_workflow.JPG\" alt=\"\" \/><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h3>The Code<\/h3>\n<p>Here is the most recent copy of the solution. You will have to compile it yourself. Make sure you understand what it is doing and adapt the code for your own purposes.<\/p>\n<p><strong>Offered as an example only with NO WARRANTY and NO SUPPORT: <\/strong><a href=\"https:\/\/www.wapshere.com\/dl\/GenerateUniqueValue%20Activity.zip\">Download Code<\/a><\/p>\n<h3>AIC Configuration<\/h3>\n<p>Activity Name: FIM.CustomWorkflowsActivityLibrary.GenerateUnique<br \/>\nAssembly Name: FIM.CustomWorkflowsActivityLibrary, version=1.0.0.0, Culture=Neutral, PublicKeyToken=abd0a8713d768ea1<br \/>\nIs Action: yes<br \/>\nTtype Name: FIM.CustomWorkflowsActivityLibrary.GenerateUniqueUI<\/p>\n<h3>Logging<\/h3>\n<p>This activity logs to the Application Event Log, but only if you first register the source liek this:<\/p>\n<p>new-eventlog -LogName &#8220;Application&#8221; -Source &#8220;FIM Custom Workflow&#8221;<\/p>\n<h3>Other Reading<\/h3>\n<p>If, like me, you&#8217;re doing this WWF development stuff for the first time, I did find <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/dd692925.aspx\">this short tutorial<\/a> very helpful. Despite my rubbishing the MSDN FIM documentation above, there is lots of good stuff there too, of course.<\/p>\n<h3>Update for FIM R2<\/h3>\n<p>This activity seems to be working fine on R2.<\/p>\n<p>If you are recompiling remember to first update the\u00c2\u00a0dlls in the\u00c2\u00a0&#8220;lib&#8221; folder\u00c2\u00a0to the versions that came with your current version of FIM.<\/p>\n<p>Also I notice I don&#8217;t have a Windows SDK folder or gacutil on my new lab server. I copied gacutil.exe from somewhere else and it works fine &#8211; only it didn&#8217;t work from Build Events where I&#8217;ve put it in this solution. I had to open a command prompt &#8220;as administrator&#8221; and run gacutil from there.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When I first started out with MIIS I found the coding heavy going &#8211; but soon realised that the same few extension-writing methods are used for pretty much everything, and the fun bit was just how much I could achieve with them! Now on to FIM and I have struggled every bit as much with&#8230;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"footnotes":"","jetpack_publicize_message":"","jetpack_is_tweetstorm":false,"jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":false,"jetpack_social_options":[]},"categories":[42,30,45],"tags":[],"class_list":["post-966","post","type-post","status-publish","format-standard","hentry","category-fim-2010","category-vbnet","category-workflow"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_shortlink":"https:\/\/wp.me\/pkp1o-fA","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/966","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/comments?post=966"}],"version-history":[{"count":32,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/966\/revisions"}],"predecessor-version":[{"id":992,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/posts\/966\/revisions\/992"}],"wp:attachment":[{"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/media?parent=966"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/categories?post=966"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wapshere.com\/missmiis\/wp-json\/wp\/v2\/tags?post=966"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}