{"id":45064,"date":"2015-05-21T07:00:00","date_gmt":"2015-05-21T21:00:00","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/oldnewthing\/2015\/05\/21\/if-you-can-set-enforcement-for-a-rule-you-can-set-up-lack-of-enforcement\/"},"modified":"2019-03-13T12:15:36","modified_gmt":"2019-03-13T19:15:36","slug":"20150521-00","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/oldnewthing\/20150521-00\/?p=45064","title":{"rendered":"If you can set enforcement for a rule, you can set up lack of enforcement"},"content":{"rendered":"<p>One of the things you can do with an internal tool I&#8217;ve been calling <i>Program&nbsp;Q<\/i> is run a program any time somebody wants to add or modify a record. The program has wide latitude in what it can do. It can inspect the record being added\/modified, maybe record side information in another table, and one of the things it can decide to do is to reject the operation. <\/p>\n<blockquote CLASS=\"q\"><p>We have set up a validator in our main table to ensure that the widget being added or modified is priced within the approver&#8217;s limit. But sometimes, there is an urgent widget request and we want to be able to bypass the validation temporarily. Is there a way to disable the validator just for a specific record, or to disable it for all records temporarily? <\/p><\/blockquote>\n<p>If you can set up a program to validate a record, you can also set up a program to <i>not<\/i> validate a record. <\/p>\n<p>Suppose your current validator for adding a widget goes like this: <\/p>\n<pre>\nif (record.approver.limit &lt; record.price) {\n record.Reject(\"Price exceeds approver's limit\");\n return;\n}\n... other tests go here ...\n<\/pre>\n<p>And say you want to be able to  allow emergency requests to go through even though, say, all approvers are unavailable. Because, maybe, the widget is on fire. <\/p>\n<p>You could decide that a widget whose description begins with the word EMERGENCY is exempt from all validation, but it generates email to a special mailing list. <\/p>\n<pre>\n<font COLOR=\"blue\">if (record.description.beginsWith(\"EMERGENCY\"))\n{\n \/\/ emergency override: send email\n \/\/ and bypass the rest of validation\n generateNotificationEmail(record);\n return;\n}<\/font>\nif (record.approver.limit &lt; record.price) {\n record.Reject(\"Price exceeds approver's limit\");\n return;\n}\n... other tests go here ...\n<\/pre>\n<p>Of course, the EMERGENCY rule was completely arbitrary. You can come up with whatever rules you like. The point is: If you wrote the rules, you can also write the rules so that they have exceptions. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>An exeption to a rule is just another rule.<\/p>\n","protected":false},"author":1069,"featured_media":111744,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[1],"tags":[26],"class_list":["post-45064","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-oldnewthing","tag-other"],"acf":[],"blog_post_summary":"<p>An exeption to a rule is just another rule.<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/45064","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/users\/1069"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/comments?post=45064"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/posts\/45064\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media\/111744"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/media?parent=45064"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/categories?post=45064"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/oldnewthing\/wp-json\/wp\/v2\/tags?post=45064"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}