{"id":791,"date":"2012-08-29T18:24:32","date_gmt":"2012-08-29T18:24:32","guid":{"rendered":"http:\/\/mahenderpal.wordpress.com\/?p=791"},"modified":"2015-10-28T12:50:51","modified_gmt":"2015-10-28T12:50:51","slug":"step-by-step-creating-custom-workflow-in-microsoft-crm-2011-part2","status":"publish","type":"post","link":"https:\/\/himbap.com\/blog\/?p=791","title":{"rendered":"Step By Step Creating Custom Workflow in Microsoft CRM &#8211; Part2"},"content":{"rendered":"<p>In previous post\u00a0we started creating custom workflow to get lead created day and assign all lead created on Sunday to Alan, we have completed code to get lead created day, so let\u2019s now write function to get user id for Alan and assign all lead to Alan if lead created day is Sunday.<\/p>\n<p>13. Create function to get userid like below<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nprivate Guid GetUserID(IOrganizationService service) \/\/function to get userid\r\n\r\n{\r\n\tGuid _UserID = Guid.Empty;\r\n\r\n\tConditionExpression condition1 = new ConditionExpression();\r\n\r\n\tcondition1.AttributeName = &quot;firstname&quot;;\r\n\r\n\tcondition1.Operator = ConditionOperator.Equal;\r\n\r\n\tcondition1.Values.Add(&quot;Alan&quot;);\r\n\r\n\tConditionExpression condition2 = new ConditionExpression();\r\n\r\n\tcondition2.AttributeName = &quot;lastname&quot;;\r\n\r\n\tcondition2.Operator = ConditionOperator.Equal;\r\n\r\n\tcondition2.Values.Add(&quot;Smith&quot;);\r\n\r\n\tFilterExpression filter1 = new FilterExpression();\r\n\r\n\tfilter1.Conditions.AddRange(condition1, condition2);\r\n\r\n\tQueryExpression query = new QueryExpression(&quot;systemuser&quot;);\r\n\r\n\tquery.Criteria.AddFilter(filter1);\r\n\r\n\tEntityCollection EntityCol = service.RetrieveMultiple(query);\r\n\r\n\tif (EntityCol.Entities.Count &gt; 0)\r\n\r\n\t{\r\n\t\tEntity _User = (Entity) EntityCol.Entities.FirstOrDefault();\r\n\r\n\t\t_UserID = _User.Id;\r\n\r\n\t}\r\n\r\n\treturn _UserID;\r\n\r\n}\r\n<\/pre>\n<p>14. Write a function to assign passed lead to Alan, like below<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nprivate void Assignlead(IOrganizationService service, Guid LeadID, Guid UserID)\r\n\r\n{\r\n\r\n\tAssignRequest _Assign = new AssignRequest() {\r\n\r\n\t\tAssignee = new EntityReference(&quot;systemuser&quot;, UserID),\r\n\r\n\t\tTarget = new EntityReference(&quot;lead&quot;, LeadID)\r\n\r\n\t};\r\n\r\n\tservice.Execute(_Assign);\r\n\r\n}\r\nfinally\u00a0we need to modify our Execute method and add below lines\r\nif (Day == &quot;Sunday&quot;)\r\n\r\n{\r\n\tGuid _UserID = GetUserID(service);\r\n\r\n\tAssignlead(service, context.PrimaryEntityId, _UserID);\r\n\r\n}\r\n<\/pre>\n<p>Our code is complete now, build your assembly and register it using plugin registration tool. While registering we can configure our step and workflow group name like below screen. Save your changes after providing these details.<\/p>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2012\/08\/providedetails.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1501 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2012\/08\/providedetails.png?w=300\" alt=\"providedetails\" width=\"300\" height=\"85\" \/><\/a><\/p>\n<p>15. Now create a workflow on lead and set it to run when &#8220;Record is created&#8221;.<\/p>\n<p>16. Click on Add Step and you should be able to see your custom workflow\u00a0there.<\/p>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2012\/08\/groupname.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1505 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2012\/08\/groupname.png?w=300\" alt=\"Groupname\" width=\"300\" height=\"165\" \/><\/a><\/p>\n<p>17. Select your assembly step to initialize your variables.<\/p>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2012\/08\/firststep.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1506 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2012\/08\/firststep.png?w=300\" alt=\"firststep\" width=\"300\" height=\"117\" \/><\/a><\/p>\n<p>18. Add an update step to update lead record and click on set properties.<\/p>\n<p>19. Selected your custom field (&#8220;Created Day&#8221;) and select your assembly name from <strong>Look For<\/strong> drop down under form assistance.<\/p>\n<p><a href=\"https:\/\/mahenderpal.files.wordpress.com\/2012\/08\/saveargument1.png\"><img decoding=\"async\" loading=\"lazy\" class=\" size-medium wp-image-1503 aligncenter\" src=\"https:\/\/mahenderpal.files.wordpress.com\/2012\/08\/saveargument1.png?w=300\" alt=\"SaveArgument\" width=\"300\" height=\"228\" \/><\/a><\/p>\n<p>20. Assign your output variable to your custom field by clicking on Add and Ok.<\/p>\n<p>Save and Activity your process, now test your workflow.<\/p>\n<p><a href=\"http:\/\/himbap.com\/\">HIMBAP<\/a>\u00a0| Need any help in Microsoft CRM <a href=\"http:\/\/www.himbap.com\/contactus.aspx\">Contact US !!<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>In previous post\u00a0we started creating custom workflow to get lead created day and assign all lead created on Sunday to Alan, we have completed code to get lead created day, so let\u2019s now write function to get user id for Alan and assign all lead to Alan if lead created day is Sunday. 13. Create function to get userid like&#8230; <a href=\"https:\/\/himbap.com\/blog\/?p=791\">Read more &raquo;<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[5,6,8,19],"tags":[55,237,238],"_links":{"self":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/791"}],"collection":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=791"}],"version-history":[{"count":5,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/791\/revisions"}],"predecessor-version":[{"id":1793,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=\/wp\/v2\/posts\/791\/revisions\/1793"}],"wp:attachment":[{"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=791"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=791"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/himbap.com\/blog\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=791"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}