{"id":22888,"date":"2020-02-20T12:37:21","date_gmt":"2020-02-20T12:37:21","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=22888"},"modified":"2020-02-20T12:37:21","modified_gmt":"2020-02-20T12:37:21","slug":"programmatically-validate-pre-post-plugin-step","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/02\/programmatically-validate-pre-post-plugin-step\/","title":{"rendered":"Programmatically validate Pre\/Post plugin step"},"content":{"rendered":"<h2><strong>Introduction<\/strong><\/h2>\n<p>In this blog, we will see how to programmatically check whether plugin step already exists or not for both Pre &amp; Post stage.<\/p>\n<p style=\"text-align: justify;\">We came across this situation when we received a requirement, where we had to programmatically register plugins. Well, the registration piece was quite easy, however, we struggled to see if the step was already registered or not.<\/p>\n<p>For this, we came up with the following solution:<br \/>\nIn order to check whether the plugin already exists or not we need to retrieve entity with specific attributes.<\/p>\n<pre class=\"lang:default decode:true \"> \/\/Variables\r\nQueryByAttribute _Query = null;\r\n\r\nRetrieveMultipleRequest _Request = null;\r\n\r\nRetrieveMultipleResponse _Response = null;\r\n\r\nEntityCollection _EntityColl = null;\r\n\r\nEntity _Entity = null;\r\n\r\n\u00a0\r\n\r\n\/\/Code\r\n\r\n\u00a0\r\n\r\n_Query = new QueryByAttribute();\r\n\r\n\u00a0\r\n\r\n_Request = new RetrieveMultipleRequest();\r\n\r\n\u00a0\r\n\r\n_Query.EntityName = \u201caccount\u201d;\r\n\r\n\u00a0\r\n\r\n_Query.ColumnSet = new ColumnSet(_RetrieveColumns);\r\n\r\n\u00a0\r\n\r\n_Query.Attributes.AddRange(_FilterByColumns);\r\n\r\n\u00a0\r\n\r\n_Query.Values.AddRange(_FilterByColumnsValue);\r\n\r\n\u00a0\r\n\r\n_Request.Query = _Query;\r\n\r\n\u00a0\r\n\r\n_Response = (RetrieveMultipleResponse)_CrmWebService.Execute(_Request);\r\n\r\n_EntityColl = _Response.EntityCollection;\r\n\r\n\u00a0\r\n\r\n\/\/Check if the EntityCollection is not empty\r\n\r\nif (_EntityColl != null &amp;&amp; _EntityColl.Entities.Count &gt; 0)\r\n\r\n{\r\n\r\n_Tracing.Trace(\"Found entity\");\r\n\r\n\/\/Return the topmost entity of the entitycollection\r\n\r\n_Entity = (Entity)_EntityColl.Entities[0];\r\n\r\n}<\/pre>\n<p>\/\/Stage is added here to check plugin is added already on pre\/post operation for selected entity \u2013 we need to pass stage as an parameter<\/p>\n<p>In above example \u201c_RetrieveColumns\u201d contain columns need to be retrieve, \u201c_FilterByColumns\u201d contains filter attributes and \u201c_FilterByColumnsValue\u201d contains filter attributes values on which we want to check.<\/p>\n<pre class=\"lang:default decode:true \">_RetrieveColumns = new string[] { \"sdkmessagefilterid\" }\r\n\r\n_FilterByColumns = new string[] { \"plugintypeid\", \"sdkmessageid\", \"sdkmessagefilterid\", <strong>\"stage\"<\/strong>}\r\n\r\n_FilterByColumnsValue = new object[] { PluginTypeEntityRef.Id, SDKMessageIdRefrence.Id, SdkMsgFiltrEntityRef.Id, SdkStep.Stage.Value };<\/pre>\n<h2><\/h2>\n<h2>Conclusion<\/h2>\n<p>Thus, with the above code you can programmatically check whether the plugin step is registered or not for pre\/post stage.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/components\/kanban-board-dynamics-365-crm\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-22892\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/02\/Kanban-Board.jpg\" alt=\"Kanban Board\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/02\/Kanban-Board.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/02\/Kanban-Board-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/02\/Kanban-Board-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/02\/Kanban-Board-660x165.jpg 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction In this blog, we will see how to programmatically check whether plugin step already exists or not for both Pre &amp; Post stage. We came across this situation when we received a requirement, where we had to programmatically register plugins. Well, the registration piece was quite easy, however, we struggled to see if the\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/02\/programmatically-validate-pre-post-plugin-step\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":22891,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[16,19,42],"tags":[2012],"class_list":["post-22888","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","category-dynamics-crm","category-plugin","tag-pre-post-plugin"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/22888","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/users\/13"}],"replies":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/comments?post=22888"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/22888\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/22891"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=22888"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=22888"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=22888"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}