alguidelines/navpatterns/1-patterns/variant-facade/index.html
2021-12-14 21:31:38 +00:00

443 lines
No EOL
53 KiB
HTML

<!doctype html><html lang=en class="js csstransforms3d">
<head>
<meta charset=utf-8>
<meta name=viewport content="width=device-width,initial-scale=1">
<meta name=generator content="Hugo 0.90.1">
<meta name=description content>
<title>Variant Facade :: AL Guidelines</title>
<link href=/css/nucleus.css?1639517494 rel=stylesheet>
<link href=/css/fontawesome-all.min.css?1639517494 rel=stylesheet>
<link href=/css/featherlight.min.css?1639517494 rel=stylesheet>
<link href=/css/perfect-scrollbar.min.css?1639517494 rel=stylesheet>
<link href=/css/auto-complete.css?1639517494 rel=stylesheet>
<link href=/css/theme.css?1639517494 rel=stylesheet>
<link href=/css/theme-blue.css?1639517494 rel=stylesheet>
<link href=/css/variant.css?1639517494 rel=stylesheet>
<link href=/css/print.css?1639517494 rel=stylesheet media=print>
<script src=/js/jquery.min.js?1639517494></script>
<style>:root #header+#content>#left>#rlblock_left{display:none!important}</style>
</head>
<body data-url=/navpatterns/1-patterns/variant-facade/>
<script>var index_url="/index.json",root_url="/",baseUri=root_url.replace(/\/$/,'')</script>
<nav id=sidebar>
<div id=header-wrapper>
<div id=header>
<a id=logo href=/ style="color:#f5f5f5;font-family:segoe ui semibold,segoe ui,SegoeUI,helvetica neue,Helvetica,Arial,sans-serif;font-size:30px;font-weight:300;margin-top:-2px">
ALGuidelines.Dev
</a>
<i style=color:#f5f5f5>Code is Poetry ...</i>
</div>
<div class=searchbox>
<label for=search-by><i class="fas fa-search"></i></label>
<input data-search-input id=search-by type=search placeholder=Search...>
<span data-search-clear><i class="fas fa-times"></i></span>
</div>
<script src=/js/lunr.min.js?1639517494></script>
<script src=/js/auto-complete.js?1639517494></script>
<script src=/js/search.js?1639517494></script>
</div>
<div class=highlightable>
<ul class=topics>
<li data-nav-id=/welcome/ title=Welcome class=dd-item><a href=/welcome/><b><i class="fas fa-home"></i> </b>Welcome</a><ul></ul></li>
<li data-nav-id=/bcpatterns/ title="BC Patterns" class=dd-item><a href=/bcpatterns/><b><i class="fas fa-clone"></i> </b>BC Patterns</a><ul>
<li data-nav-id=/bcpatterns/facade-pattern/ title="Facade Pattern" class=dd-item><a href=/bcpatterns/facade-pattern/>Facade Pattern</a></li>
<li data-nav-id=/bcpatterns/generic-method-pattern/ title="Generic Method Pattern" class=dd-item><a href=/bcpatterns/generic-method-pattern/>Generic Method Pattern</a></li></ul></li>
<li data-nav-id=/bcbestpractices/ title="BC Dev. Best Practices" class=dd-item><a href=/bcbestpractices/><b><i class="fas fa-medal"></i> </b>BC Dev. Best Practices</a><ul>
<li data-nav-id=/bcbestpractices/readability/ title=Readability class=dd-item><a href=/bcbestpractices/readability/>Readability</a><ul>
<li data-nav-id=/bcbestpractices/readability/begin-as-an-afterword/ title="begin as an 'After Word'" class=dd-item><a href=/bcbestpractices/readability/begin-as-an-afterword/>begin as an 'After Word'</a></li>
<li data-nav-id=/bcbestpractices/readability/begin-end/ title="Begin-End - Compound Only" class=dd-item><a href=/bcbestpractices/readability/begin-end/>Begin-End - Compound Only</a></li>
<li data-nav-id=/bcbestpractices/readability/binary-operator-line-start/ title="Binary Operator to Start Line" class=dd-item><a href=/bcbestpractices/readability/binary-operator-line-start/>Binary Operator to Start Line</a></li>
<li data-nav-id=/bcbestpractices/readability/comments-spacing/ title="Comment Spacing" class=dd-item><a href=/bcbestpractices/readability/comments-spacing/>Comment Spacing</a></li>
<li data-nav-id=/bcbestpractices/readability/end-else-pair/ title="end else pair" class=dd-item><a href=/bcbestpractices/readability/end-else-pair/>end else pair</a></li>
<li data-nav-id=/bcbestpractices/readability/keyword-pairs-indentation/ title="Keyword Pairs - Indentation" class=dd-item><a href=/bcbestpractices/readability/keyword-pairs-indentation/>Keyword Pairs - Indentation</a></li>
<li data-nav-id=/bcbestpractices/readability/lonely-repeat/ title="Lonely Repeat" class=dd-item><a href=/bcbestpractices/readability/lonely-repeat/>Lonely Repeat</a></li>
<li data-nav-id=/bcbestpractices/readability/named-invocations/ title="Named Invocations" class=dd-item><a href=/bcbestpractices/readability/named-invocations/>Named Invocations</a></li>
<li data-nav-id=/bcbestpractices/readability/one-statement-per-line/ title="One Statement Per Line" class=dd-item><a href=/bcbestpractices/readability/one-statement-per-line/>One Statement Per Line</a></li>
<li data-nav-id=/bcbestpractices/readability/separate-if-and-else/ title="Separate if and else" class=dd-item><a href=/bcbestpractices/readability/separate-if-and-else/>Separate if and else</a></li>
<li data-nav-id=/bcbestpractices/readability/spacing-binary-operators/ title="Spacing Binary Operators" class=dd-item><a href=/bcbestpractices/readability/spacing-binary-operators/>Spacing Binary Operators</a></li>
<li data-nav-id=/bcbestpractices/readability/suggested-abbreviations/ title="Suggested Abbreviations" class=dd-item><a href=/bcbestpractices/readability/suggested-abbreviations/>Suggested Abbreviations</a></li>
<li data-nav-id=/bcbestpractices/readability/unnecessary-else/ title="Unnecessary 'else'" class=dd-item><a href=/bcbestpractices/readability/unnecessary-else/>Unnecessary 'else'</a></li>
<li data-nav-id=/bcbestpractices/readability/unnecessary-truefalse/ title="Unnecessary true/false" class=dd-item><a href=/bcbestpractices/readability/unnecessary-truefalse/>Unnecessary true/false</a></li>
<li data-nav-id=/bcbestpractices/readability/variable-naming/ title="Variable Naming" class=dd-item><a href=/bcbestpractices/readability/variable-naming/>Variable Naming</a></li>
<li data-nav-id=/bcbestpractices/readability/variables-declarations-order/ title="Variables Declarations Order" class=dd-item><a href=/bcbestpractices/readability/variables-declarations-order/>Variables Declarations Order</a></li></ul></li></ul></li>
<li data-nav-id=/navpatterns/ title="NAV Patterns Archive" class="dd-item parent"><a href=/navpatterns/><b><i class="fas fa-save"></i> </b>NAV Patterns Archive</a><ul>
<li data-nav-id=/navpatterns/1-patterns/ title="1. Patterns" class="dd-item parent"><a href=/navpatterns/1-patterns/>1. Patterns</a><ul>
<li data-nav-id=/navpatterns/1-patterns/activity-log/ title="Activity Logs" class=dd-item><a href=/navpatterns/1-patterns/activity-log/>Activity Logs</a></li>
<li data-nav-id=/navpatterns/1-patterns/argument-table/ title="Argument Table" class=dd-item><a href=/navpatterns/1-patterns/argument-table/>Argument Table</a></li>
<li data-nav-id=/navpatterns/1-patterns/blocked-entity/ title="Blocked Entity" class=dd-item><a href=/navpatterns/1-patterns/blocked-entity/>Blocked Entity</a><ul>
<li data-nav-id=/navpatterns/1-patterns/blocked-entity/data-driven-blocked-entity/ title="Data Driven Blocked Entity" class=dd-item><a href=/navpatterns/1-patterns/blocked-entity/data-driven-blocked-entity/>Data Driven Blocked Entity</a></li></ul></li>
<li data-nav-id=/navpatterns/1-patterns/cached-web-service-calls/ title="Cached Web Server Calls" class=dd-item><a href=/navpatterns/1-patterns/cached-web-service-calls/>Cached Web Server Calls</a></li>
<li data-nav-id=/navpatterns/1-patterns/conditional-cascading-update/ title="Conditional Cascading Update" class=dd-item><a href=/navpatterns/1-patterns/conditional-cascading-update/>Conditional Cascading Update</a></li>
<li data-nav-id=/navpatterns/1-patterns/copy-document/ title="Copy Document" class=dd-item><a href=/navpatterns/1-patterns/copy-document/>Copy Document</a></li>
<li data-nav-id=/navpatterns/1-patterns/create-data-from-templates/ title="Create Data from Templates" class=dd-item><a href=/navpatterns/1-patterns/create-data-from-templates/>Create Data from Templates</a></li>
<li data-nav-id=/navpatterns/1-patterns/create-urls-to-nav-clients/ title="Create URLs to NAV Clients" class=dd-item><a href=/navpatterns/1-patterns/create-urls-to-nav-clients/>Create URLs to NAV Clients</a></li>
<li data-nav-id=/navpatterns/1-patterns/creating-custom-charts/ title="Creating Custom Charts" class=dd-item><a href=/navpatterns/1-patterns/creating-custom-charts/>Creating Custom Charts</a></li>
<li data-nav-id=/navpatterns/1-patterns/cross-session-events/ title="Cross Session Events" class=dd-item><a href=/navpatterns/1-patterns/cross-session-events/>Cross Session Events</a></li>
<li data-nav-id=/navpatterns/1-patterns/currently-active-record/ title="Currently Active Record" class=dd-item><a href=/navpatterns/1-patterns/currently-active-record/>Currently Active Record</a></li>
<li data-nav-id=/navpatterns/1-patterns/data-migration-facade/ title="Data Migration Façade" class=dd-item><a href=/navpatterns/1-patterns/data-migration-facade/>Data Migration Façade</a></li>
<li data-nav-id=/navpatterns/1-patterns/discovery-event/ title="Discovery Event" class=dd-item><a href=/navpatterns/1-patterns/discovery-event/>Discovery Event</a></li>
<li data-nav-id=/navpatterns/1-patterns/document/ title=Document class=dd-item><a href=/navpatterns/1-patterns/document/>Document</a></li>
<li data-nav-id=/navpatterns/1-patterns/easy-update-of-setup-or-supplementary-information/ title="Easy Update Of Setup Or Supplementary Information" class=dd-item><a href=/navpatterns/1-patterns/easy-update-of-setup-or-supplementary-information/>Easy Update Of Setup Or Supplementary Information</a></li>
<li data-nav-id=/navpatterns/1-patterns/error-message-processing/ title="Error Message Processing" class=dd-item><a href=/navpatterns/1-patterns/error-message-processing/>Error Message Processing</a></li>
<li data-nav-id=/navpatterns/1-patterns/extending-the-role-center-headlines/ title="Extending the Role Center Headlines" class=dd-item><a href=/navpatterns/1-patterns/extending-the-role-center-headlines/>Extending the Role Center Headlines</a></li>
<li data-nav-id=/navpatterns/1-patterns/feature-localization-for-data-structures/ title="Feature Localization For Data Structures" class=dd-item><a href=/navpatterns/1-patterns/feature-localization-for-data-structures/>Feature Localization For Data Structures</a></li>
<li data-nav-id=/navpatterns/1-patterns/hooks/ title=Hooks class=dd-item><a href=/navpatterns/1-patterns/hooks/>Hooks</a></li>
<li data-nav-id=/navpatterns/1-patterns/implementation-of-surrogate-keys-using-autoincrement-pattern/ title="Surrogate keys using Autoincrement Pattern" class=dd-item><a href=/navpatterns/1-patterns/implementation-of-surrogate-keys-using-autoincrement-pattern/>Surrogate keys using Autoincrement Pattern</a></li>
<li data-nav-id=/navpatterns/1-patterns/instructions-in-the-ui/ title="Instructions in the UI" class=dd-item><a href=/navpatterns/1-patterns/instructions-in-the-ui/>Instructions in the UI</a></li>
<li data-nav-id=/navpatterns/1-patterns/integration-of-addresses/ title="Integration of Addresses" class=dd-item><a href=/navpatterns/1-patterns/integration-of-addresses/>Integration of Addresses</a></li>
<li data-nav-id=/navpatterns/1-patterns/journal-error-processing/ title="Journal Error Processing" class=dd-item><a href=/navpatterns/1-patterns/journal-error-processing/>Journal Error Processing</a></li>
<li data-nav-id=/navpatterns/1-patterns/journal-template-batch-line/ title="Journal Template Batch Line" class=dd-item><a href=/navpatterns/1-patterns/journal-template-batch-line/>Journal Template Batch Line</a></li>
<li data-nav-id=/navpatterns/1-patterns/master-data/ title="Master Data" class=dd-item><a href=/navpatterns/1-patterns/master-data/>Master Data</a></li>
<li data-nav-id=/navpatterns/1-patterns/multi-file-download/ title="Multi-file Download" class=dd-item><a href=/navpatterns/1-patterns/multi-file-download/>Multi-file Download</a></li>
<li data-nav-id=/navpatterns/1-patterns/multi-page-list/ title="Multi-Page List" class=dd-item><a href=/navpatterns/1-patterns/multi-page-list/>Multi-Page List</a></li>
<li data-nav-id=/navpatterns/1-patterns/multilanguage-application-data/ title="Multilanguage Application Data" class=dd-item><a href=/navpatterns/1-patterns/multilanguage-application-data/>Multilanguage Application Data</a></li>
<li data-nav-id=/navpatterns/1-patterns/net-exception-handling-in-cal/ title="NET Exception Handling in CAL" class=dd-item><a href=/navpatterns/1-patterns/net-exception-handling-in-cal/>NET Exception Handling in CAL</a><ul>
<li data-nav-id=/navpatterns/1-patterns/net-exception-handling-in-cal/tryfunction-net-exception-handling-in-cal/ title="TryFunction NET Exception Handling in CAL" class=dd-item><a href=/navpatterns/1-patterns/net-exception-handling-in-cal/tryfunction-net-exception-handling-in-cal/>TryFunction NET Exception Handling in CAL</a></li></ul></li>
<li data-nav-id=/navpatterns/1-patterns/no-series/ title="No Series" class=dd-item><a href=/navpatterns/1-patterns/no-series/>No Series</a></li>
<li data-nav-id=/navpatterns/1-patterns/notifications/ title=Notifications class=dd-item><a href=/navpatterns/1-patterns/notifications/>Notifications</a><ul>
<li data-nav-id=/navpatterns/1-patterns/notifications/in-context-notifications/ title="In-context Notifications" class=dd-item><a href=/navpatterns/1-patterns/notifications/in-context-notifications/>In-context Notifications</a></li>
<li data-nav-id=/navpatterns/1-patterns/notifications/notification-lifecycle-management-pattern/ title="Notification Lifecycle Management Pattern" class=dd-item><a href=/navpatterns/1-patterns/notifications/notification-lifecycle-management-pattern/>Notification Lifecycle Management Pattern</a></li></ul></li>
<li data-nav-id=/navpatterns/1-patterns/observer/ title=Observer class=dd-item><a href=/navpatterns/1-patterns/observer/>Observer</a></li>
<li data-nav-id=/navpatterns/1-patterns/posting-routine-select-behavior/ title="Posting Routine - Select Behavior" class=dd-item><a href=/navpatterns/1-patterns/posting-routine-select-behavior/>Posting Routine - Select Behavior</a></li>
<li data-nav-id=/navpatterns/1-patterns/product-name/ title="Product Name" class=dd-item><a href=/navpatterns/1-patterns/product-name/>Product Name</a></li>
<li data-nav-id=/navpatterns/1-patterns/queries/ title=Queries class=dd-item><a href=/navpatterns/1-patterns/queries/>Queries</a><ul>
<li data-nav-id=/navpatterns/1-patterns/queries/select-distinct-with-queries/ title="SELECT DISTINCT with Queries" class=dd-item><a href=/navpatterns/1-patterns/queries/select-distinct-with-queries/>SELECT DISTINCT with Queries</a></li>
<li data-nav-id=/navpatterns/1-patterns/queries/use-queries-to-detect-duplicate-records/ title="Use Queries to Detect Duplicate Records" class=dd-item><a href=/navpatterns/1-patterns/queries/use-queries-to-detect-duplicate-records/>Use Queries to Detect Duplicate Records</a></li>
<li data-nav-id=/navpatterns/1-patterns/queries/use-queries-to-replace-nested-loops/ title="Use Queries to Replace Nested Loops" class=dd-item><a href=/navpatterns/1-patterns/queries/use-queries-to-replace-nested-loops/>Use Queries to Replace Nested Loops</a></li></ul></li>
<li data-nav-id=/navpatterns/1-patterns/read-once-initialization-and-validation/ title="Read-once Initialization and Validation" class=dd-item><a href=/navpatterns/1-patterns/read-once-initialization-and-validation/>Read-once Initialization and Validation</a></li>
<li data-nav-id=/navpatterns/1-patterns/released-entity/ title="Released Entity" class=dd-item><a href=/navpatterns/1-patterns/released-entity/>Released Entity</a></li>
<li data-nav-id=/navpatterns/1-patterns/report-selection/ title="Report Selection" class=dd-item><a href=/navpatterns/1-patterns/report-selection/>Report Selection</a></li>
<li data-nav-id=/navpatterns/1-patterns/security/ title=Security class=dd-item><a href=/navpatterns/1-patterns/security/>Security</a><ul>
<li data-nav-id=/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/ title="Sensitive Data Encapsulation" class=dd-item><a href=/navpatterns/1-patterns/security/1-sensitive-data-encapsulation/>Sensitive Data Encapsulation</a></li>
<li data-nav-id=/navpatterns/1-patterns/security/2-data-encryption/ title="Data Encryption" class=dd-item><a href=/navpatterns/1-patterns/security/2-data-encryption/>Data Encryption</a></li>
<li data-nav-id=/navpatterns/1-patterns/security/3-single-point-of-access/ title="Single Point of Access" class=dd-item><a href=/navpatterns/1-patterns/security/3-single-point-of-access/>Single Point of Access</a></li>
<li data-nav-id=/navpatterns/1-patterns/security/4-masked-text/ title="Masked Text" class=dd-item><a href=/navpatterns/1-patterns/security/4-masked-text/>Masked Text</a></li>
<li data-nav-id=/navpatterns/1-patterns/security/5-ssl-in-nav/ title="SSL in NAV" class=dd-item><a href=/navpatterns/1-patterns/security/5-ssl-in-nav/>SSL in NAV</a></li></ul></li>
<li data-nav-id=/navpatterns/1-patterns/setup-specificity-fallback/ title="Setup Specificity Fallback" class=dd-item><a href=/navpatterns/1-patterns/setup-specificity-fallback/>Setup Specificity Fallback</a></li>
<li data-nav-id=/navpatterns/1-patterns/silent-file-upload-and-download/ title="Silent File Upload and Download" class=dd-item><a href=/navpatterns/1-patterns/silent-file-upload-and-download/>Silent File Upload and Download</a></li>
<li data-nav-id=/navpatterns/1-patterns/singleton/ title=Singleton class=dd-item><a href=/navpatterns/1-patterns/singleton/>Singleton</a><ul>
<li data-nav-id=/navpatterns/1-patterns/singleton/singleton-codeunit/ title="Singleton Codeunit" class=dd-item><a href=/navpatterns/1-patterns/singleton/singleton-codeunit/>Singleton Codeunit</a></li>
<li data-nav-id=/navpatterns/1-patterns/singleton/singleton-table/ title="Singleton Table" class=dd-item><a href=/navpatterns/1-patterns/singleton/singleton-table/>Singleton Table</a><ul>
<li data-nav-id=/navpatterns/1-patterns/singleton/singleton-table/cue-table/ title="Cue Table" class=dd-item><a href=/navpatterns/1-patterns/singleton/singleton-table/cue-table/>Cue Table</a></li>
<li data-nav-id=/navpatterns/1-patterns/singleton/singleton-table/setup-table/ title="Setup Table" class=dd-item><a href=/navpatterns/1-patterns/singleton/singleton-table/setup-table/>Setup Table</a></li></ul></li></ul></li>
<li data-nav-id=/navpatterns/1-patterns/standard-journal/ title="Standard Journal" class=dd-item><a href=/navpatterns/1-patterns/standard-journal/>Standard Journal</a></li>
<li data-nav-id=/navpatterns/1-patterns/temporary-dataset-report/ title="Temporary Dataset Report" class=dd-item><a href=/navpatterns/1-patterns/temporary-dataset-report/>Temporary Dataset Report</a></li>
<li data-nav-id=/navpatterns/1-patterns/totals-and-discounts-on-subpages-sales-and-purchases/ title="Totals and Discounts on Subpages Sales and Purchases" class=dd-item><a href=/navpatterns/1-patterns/totals-and-discounts-on-subpages-sales-and-purchases/>Totals and Discounts on Subpages Sales and Purchases</a></li>
<li data-nav-id=/navpatterns/1-patterns/transfer-custom-fields/ title="Transfer Custom Fields" class=dd-item><a href=/navpatterns/1-patterns/transfer-custom-fields/>Transfer Custom Fields</a></li>
<li data-nav-id=/navpatterns/1-patterns/variant-facade/ title="Variant Facade" class="dd-item active"><a href=/navpatterns/1-patterns/variant-facade/>Variant Facade</a></li></ul></li>
<li data-nav-id=/navpatterns/2-anti-patterns/ title="2. Anti-Patterns" class=dd-item><a href=/navpatterns/2-anti-patterns/>2. Anti-Patterns</a><ul>
<li data-nav-id=/navpatterns/2-anti-patterns/nav-upgrade/ title="Nav Upgrade" class=dd-item><a href=/navpatterns/2-anti-patterns/nav-upgrade/>Nav Upgrade</a></li>
<li data-nav-id=/navpatterns/2-anti-patterns/reusable-bugs/ title="Reusable Bugs" class=dd-item><a href=/navpatterns/2-anti-patterns/reusable-bugs/>Reusable Bugs</a></li></ul></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/ title="3. CAL Coding Guidelines" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/>3. CAL Coding Guidelines</a><ul>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/ title=Design class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/>Design</a><ul>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/by-reference-parameters/ title="By Reference Parameters" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/by-reference-parameters/>By Reference Parameters</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/class-coupling/ title="Class Coupling" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/class-coupling/>Class Coupling</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/cyclomatic-complexity/ title="Cyclomatic Complexity" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/cyclomatic-complexity/>Cyclomatic Complexity</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/encapsulate-local-functionality/ title="Encapsulate Local Functionality" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/encapsulate-local-functionality/>Encapsulate Local Functionality</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/findset-findfirst-findlast/ title="FINDSET FINDFIRST FINDLAST" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/findset-findfirst-findlast/>FINDSET FINDFIRST FINDLAST</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/initialized-variables/ title="Initialized Variables" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/initialized-variables/>Initialized Variables</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/maintainability-index/ title="Maintainability Index" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/maintainability-index/>Maintainability Index</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/parameter-placeholders/ title="Parameter Placeholders" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/parameter-placeholders/>Parameter Placeholders</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/static-object-invocation/ title="Static Object Invocation" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/static-object-invocation/>Static Object Invocation</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/unreachable-code/ title="Unreachable Code" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/unreachable-code/>Unreachable Code</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/unused-initialized-variables/ title="Unused Initialized Variables" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/unused-initialized-variables/>Unused Initialized Variables</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/unused-variables/ title="Unused Variables" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/unused-variables/>Unused Variables</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/variable-capacity-mismatch/ title="Variable Capacity Mismatch" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/variable-capacity-mismatch/>Variable Capacity Mismatch</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/design/with-scope-name-collision/ title="WITH Scope Name Collision" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/design/with-scope-name-collision/>WITH Scope Name Collision</a></li></ul></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/internally-used-dot-net-types/ title="Internally used DotNet Types" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/internally-used-dot-net-types/>Internally used DotNet Types</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/internationalization/ title=Internationalization class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/internationalization/>Internationalization</a><ul>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/internationalization/using-calcdate/ title="Using Calcdate" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/internationalization/using-calcdate/>Using Calcdate</a></li></ul></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/localizability/ title=Localizability class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/localizability/>Localizability</a><ul>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/localizability/captionml-for-system-tables/ title="CaptionML on System Pages" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/localizability/captionml-for-system-tables/>CaptionML on System Pages</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/localizability/fieldcaption-and-tablecaption/ title="FIELDCAPTION and TABLECAPTION" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/localizability/fieldcaption-and-tablecaption/>FIELDCAPTION and TABLECAPTION</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/localizability/global-text-constants/ title="Global Text Constants" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/localizability/global-text-constants/>Global Text Constants</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/localizability/use-text-constants/ title="Use Text Constants" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/localizability/use-text-constants/>Use Text Constants</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/localizability/using-optioncaptionml/ title="Using OptionCaptionML" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/localizability/using-optioncaptionml/>Using OptionCaptionML</a></li></ul></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/ title=Readability class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/>Readability</a><ul>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/begin-as-an-afterword/ title="Begin as an 'After Word'" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/begin-as-an-afterword/>Begin as an 'After Word'</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/begin-end/ title="Begin-End - Compound Only" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/begin-end/>Begin-End - Compound Only</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/binary-operator-line-start/ title="Binary Operator to Start Line" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/binary-operator-line-start/>Binary Operator to Start Line</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/blank-lines/ title="Blank Lines" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/blank-lines/>Blank Lines</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/case-actions/ title="CASE Action" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/case-actions/>CASE Action</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/colon-usage-in-case/ title="Colon usage in CASE" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/colon-usage-in-case/>Colon usage in CASE</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/comments-curly-brackets/ title="Comments inside Curly Brackets" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/comments-curly-brackets/>Comments inside Curly Brackets</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/comments-spacing/ title="Comment Spacing" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/comments-spacing/>Comment Spacing</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/end-else-pair/ title="END ELSE Pair" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/end-else-pair/>END ELSE Pair</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/indentation/ title=Indentation class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/indentation/>Indentation</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/keyword-pairs-indentation/ title="Keyword Pairs - Indentation" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/keyword-pairs-indentation/>Keyword Pairs - Indentation</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/line-start-keywords/ title="Line Start Keywords" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/line-start-keywords/>Line Start Keywords</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/lonely-repeat/ title="Lonely Repeat" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/lonely-repeat/>Lonely Repeat</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/named-invocations/ title="Named Invocations" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/named-invocations/>Named Invocations</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/nested-withs/ title="Nested WITHs" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/nested-withs/>Nested WITHs</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/one-statement-per-line/ title="One Statement Per Line" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/one-statement-per-line/>One Statement Per Line</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/separate-if-and-else/ title="Separate IF and ELSE" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/separate-if-and-else/>Separate IF and ELSE</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/spacing-binary-operators/ title="Spacing Binary Operators" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/spacing-binary-operators/>Spacing Binary Operators</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/spacing-brackets-and/ title="Spacing Brackets and ::" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/spacing-brackets-and/>Spacing Brackets and ::</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/spacing-unary-operators/ title="Spacing Unary Operators" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/spacing-unary-operators/>Spacing Unary Operators</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/suggested-abbreviations/ title="Suggested Abbreviations" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/suggested-abbreviations/>Suggested Abbreviations</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/temporary-variable-naming/ title="Temporary Variable Naming" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/temporary-variable-naming/>Temporary Variable Naming</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/textconst-suffixes/ title="TextConst Suffixes" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/textconst-suffixes/>TextConst Suffixes</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/unary-operator-line-end/ title="Unary Operator Line End" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/unary-operator-line-end/>Unary Operator Line End</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-compound-parenthesis/ title="Unnecessary Compound Parenthesis" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-compound-parenthesis/>Unnecessary Compound Parenthesis</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-else/ title="Unnecessary ELSE" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-else/>Unnecessary ELSE</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-function-parenthesis/ title="Unnecessary Function Parenthesis" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-function-parenthesis/>Unnecessary Function Parenthesis</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-separators/ title="Unnecessary Separators" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-separators/>Unnecessary Separators</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-truefalse/ title="Unnecessary TRUE/FALSE" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/unnecessary-truefalse/>Unnecessary TRUE/FALSE</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/variable-already-scoped/ title="Variable Already Scoped" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/variable-already-scoped/>Variable Already Scoped</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/variable-naming/ title="Variable Naming" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/variable-naming/>Variable Naming</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/readability/variables-declarations-order/ title="Variables Declarations Order" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/readability/variables-declarations-order/>Variables Declarations Order</a></li></ul></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/ux/ title=UX class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/ux/>UX</a><ul>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/ux/actions-images/ title="Actions - Images" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/ux/actions-images/>Actions - Images</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/ux/confirm/ title=CONFIRM class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/ux/confirm/>CONFIRM</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/ux/fielderror/ title=FIELDERROR class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/ux/fielderror/>FIELDERROR</a></li>
<li data-nav-id=/navpatterns/3-cal-coding-guidelines/ux/message-and-error/ title="MESSAGE and ERROR" class=dd-item><a href=/navpatterns/3-cal-coding-guidelines/ux/message-and-error/>MESSAGE and ERROR</a></li></ul></li></ul></li>
<li data-nav-id=/navpatterns/4-get-involved/ title="(OLD) Get Involved" class=dd-item><a href=/navpatterns/4-get-involved/>(OLD) Get Involved</a><ul>
<li data-nav-id=/navpatterns/4-get-involved/code-of-conduct/ title="Code of Conduct" class=dd-item><a href=/navpatterns/4-get-involved/code-of-conduct/>Code of Conduct</a></li>
<li data-nav-id=/navpatterns/4-get-involved/patterns-authors/ title="Patterns Authors" class=dd-item><a href=/navpatterns/4-get-involved/patterns-authors/>Patterns Authors</a></li>
<li data-nav-id=/navpatterns/4-get-involved/template-for-writing-nav-design-patterns/ title="Template for writing Nav Design Patterns" class=dd-item><a href=/navpatterns/4-get-involved/template-for-writing-nav-design-patterns/>Template for writing Nav Design Patterns</a></li></ul></li>
<li data-nav-id=/navpatterns/related-links/ title="Related Links" class=dd-item><a href=/navpatterns/related-links/>Related Links</a></li></ul></li>
<li data-nav-id=/contributing/ title=Contributing class=dd-item><a href=/contributing/><b><i class="fas fa-clone"></i> </b>Contributing</a><ul>
<li data-nav-id=/contributing/formattingtips/ title="Formatting tips" class=dd-item><a href=/contributing/formattingtips/><b><i class="fas fa-clone"></i> </b>Formatting tips</a></li>
<li data-nav-id=/contributing/forkandpr/ title="Guide to Fork & PR" class=dd-item><a href=/contributing/forkandpr/><b><i class="fas fa-clone"></i> </b>Guide to Fork & PR</a></li>
<li data-nav-id=/contributing/templates/ title=Templates class=dd-item><a href=/contributing/templates/><b><i class="fas fa-clone"></i> </b>Templates</a><ul>
<li data-nav-id=/contributing/templates/guidelines/ title="Title of the Guideline" class=dd-item><a href=/contributing/templates/guidelines/>Title of the Guideline</a></li>
<li data-nav-id=/contributing/templates/patterns/ title="Title of the pattern" class=dd-item><a href=/contributing/templates/patterns/>Title of the pattern</a></li></ul></li>
<li data-nav-id=/contributing/theapprovalprocess/ title="Understanding the Approval Process" class=dd-item><a href=/contributing/theapprovalprocess/><b><i class="fas fa-clone"></i> </b>Understanding the Approval Process</a></li></ul></li>
</ul>
<div id=shortcuts>
<div class=nav-title>More</div>
<ul>
<li><a class=padding href=https://discord.gg/4wbfNv3><i class="fab fa-discord"></i> BC Discord</a></li>
<li><a class=padding href=https://github.com/microsoft/alguidelines><i class="fab fa-github"></i> GitHub repo</a></li>
</ul>
</div>
<div id=footer>
<p>Built with <a href=https://github.com/McShelby/hugo-theme-relearn><i class="fas fa-heart"></i></a> by <a href=https://gohugo.io/>Hugo</a></p>
</div>
</div>
</nav>
<div id=body>
<div id=overlay></div>
<div class="padding highlightable">
<div id=top-bar>
<div id=top-github-link>
<a class=github-link title="Edit this page" href=https://github.com/microsoft/alguidelines/edit/main/content/NAVPatterns/1-patterns/variant-facade/index.md target=blank>
<i class="fas fa-code-branch"></i>
<span id=top-github-link-text>Edit this page</span>
</a>
</div>
<div id=breadcrumbs>
<span id=sidebar-toggle-span>
<a href=# id=sidebar-toggle data-sidebar-toggle>
<i class="fas fa-bars"></i>
</a>
</span>
<span id=toc-menu><i class="fas fa-list-alt"></i></span>
<ol class=links itemscope itemtype=http://schema.org/BreadcrumbList>
<meta itemprop=itemListOrder content="Descending">
<li itemscope itemtype=https://schema.org/ListItem itemprop=itemListElement><meta itemprop=position content="4"><a itemprop=item href=/><span itemprop=name>Home</span></a> > </li>
<li itemscope itemtype=https://schema.org/ListItem itemprop=itemListElement><meta itemprop=position content="3"><a itemprop=item href=/navpatterns/><span itemprop=name>NAV Patterns Archive</span></a> > </li>
<li itemscope itemtype=https://schema.org/ListItem itemprop=itemListElement><meta itemprop=position content="2"><a itemprop=item href=/navpatterns/1-patterns/><span itemprop=name>1. Patterns</span></a> > </li>
<li itemscope itemtype=https://schema.org/ListItem itemprop=itemListElement><meta itemprop=position content="1"><a itemprop=item href=/navpatterns/1-patterns/variant-facade/ aria-disabled=true><span itemprop=name>Variant Facade</span></a></li>
</ol>
</div>
<div class=progress>
<div class=wrapper>
<nav id=TableOfContents>
<ul>
<li><a href=#signature>Signature</a></li>
<li><a href=#casting-to-a-record-ref>Casting to a record ref</a></li>
<li><a href=#using-the-variant>Using the variant</a></li>
<li><a href=#table-specific-code>Table specific code</a></li>
</ul>
</nav>
</div>
</div>
</div>
<div id=head-tags>
</div>
<main id=body-inner>
<h1>Variant Facade</h1>
<p><em>By Nikola Kukrika, waldo and Gary Winter</em></p>
<h1 id=abstract>Abstract</h1>
<p>The Variant façade provides a single interface that can take any Record, RecordRef or RecordID as an argument. With this pattern the code is encapsulated within the single object, with clear separation between common and table specific code.</p>
<p><a href=picture1.png><img src=picture1.png alt=" "></a></p>
<hr>
<h1 id=problem>Problem</h1>
<p>Since NAV is strongly typed, developers often need to duplicate functionality in order to add support for a new table. The developer would typically start by duplicating the function, changing the record type and implement slight modifications to the code if needed.</p>
<p>The problem with this approach is that code duplication is one of the worst things in software development &ndash; it makes code harder to understand, maintain, extend and test.</p>
<p>One of the good examples of this approach and the resulting duplication is codeunit 229, Document-Print:</p>
<p><a href=Picture2.png><img src=Picture2.png alt=" "></a></p>
<p><a href=Picture3.png><img src=Picture3.png alt=" "></a></p>
<p>After reading the code from the two code snippets above, it is very hard to see the differences. The most of the code is duplicated (more than 95%). To make the matters worse the codeunit itself has 10 additional methods that are used to print different records, some are similar to the ones above while others are completely different.</p>
<p><a href=Picture4.png><img src=Picture4.png alt=" "></a></p>
<p><a href=Picture5.png><img src=Picture5.png alt=" "></a></p>
<p>Figure: the entire code of the codeunit 229, Document Print, 12 methods</p>
<p><a href=Picture6.png><img src=Picture6.png alt=" "></a></p>
<p>Figure: Visualization how it would look like with 20 methods</p>
<p>Problems arising from this way of implementing code are:</p>
<p><strong>Understanding of the code</strong> is very hard, since the developer needs to read blocks of code that look similar and try to understand what exactly the differences are.</p>
<p><strong>Maintaining and Extending</strong> the code is hard, since every fix or a new behavior that needs to be implemented multiple times (in this case probably 12 times).</p>
<p><strong>Upgradability is low</strong> &ndash; each conflict needs to be resolved many times. The hook pattern is hard to implement since it needs to be implemented for every function. Evening suffers the same problem - cannot use the evening easily since it needs to be raised from multiple places in the code.</p>
<p><strong>Testing the code</strong> is hard since the tests need to be replicated.</p>
<p><strong>Constant cost of adding support for new tables</strong> &ndash; when the new record type needs to be supported, it has a constant cost. Adding a support for a new record will increase the Maintenance tax and it will make the code harder to understand and extend.</p>
<p><strong>Conclusion</strong> - <strong>If the functionality needs to be used for many records the approach of duplicating the functions should be avoided.</strong></p>
<h1 id=solution>Solution</h1>
<p>The Variant façade pattern provides a single interface that would not need to be changed in the future. It will be able to take any record as a parameter. Common code should be kept separately from record specific code and both must be very visible so the developers can easily see what the differences are.</p>
<p>The Key components of the pattern are:</p>
<h2 id=signature>Signature</h2>
<p>Instead of hardcoding a record type a variant is used as an argument. A Variant Façade function can receive three types of data: Record, RecordID, or RecordRef. This way, it can be reused anywhere in the product and the code will still work.</p>
<p>A good practice is to combine this pattern with the Argument Table pattern to make sure that the signature does not change (Additional parameters can be added to the argument table without impacting existing code.). If the Argument Table is not needed, it should not be placed in the signature - it is always possible to add it at a latter point and have two public functions (one with and one without arguments).</p>
<p>Example - For codeunit 229, Document-Print all of the public methods can be simply replaced with a single public method like this:</p>
<p>With this approach the façade function can serve all of the record types and will not need to change in the future.</p>
<h2 id=casting-to-a-record-ref>Casting to a record ref</h2>
<p>After the signature it is necessary to decide if the function will support passing of the Record ID and the RecordRef. Code tends to be easier to understand and maintain if only the records are passed as the arguments, however in some cases it is needed to support the other two types.</p>
<ul>
<li><strong>Support for Record, Record ID and RecordRef:</strong></li>
</ul>
<p>After the signature if the function supports passing of the RecordID or RecordRef as a parameter it is a good practice to cast them to a RecordRef. Codeunit Data Type Management is used to do this:</p>
<p>DataTypeManagement.GetRecordRef(RecRelatedVariant,RecordRef)</p>
<ul>
<li><strong>Support Records only</strong> - If the function supports only passing in the record, it is a good practice to check if the variant is a record:</li>
</ul>
<p>IF NOT RecordVariant.ISRECORD THEN</p>
<p>ERROR(NotARecordErr);</p>
<h2 id=using-the-variant>Using the variant</h2>
<p>The variant can be passed instead of record when calling the Page.RUN, Codeunit.RUN or Report.RUN statically:</p>
<p>For example:</p>
<p>Page.RUN(PageID,Variant);</p>
<p>Codeunit.RUN(CodeunitID,Variant);</p>
<p>Report.RUN(ReportID,Variant);</p>
<p>These calls are identical to using an actual instance of the record, since the variant will be casted to the record automatically, with all filters, markings and values preserved.</p>
<hr>
<p>In case the variant was casted to the RecordRef (by using DataTypeManagement.GetRecordRef(RecRelatedVariant,RecordRef)), it is still possible to invoke the functions statically.</p>
<p>The RecordRef simply needs to be casted into a variant and passed as a parameter, for example:</p>
<p>VariantArgument := RecordRef;</p>
<p>Page.RUN(PageID,VariantArgument);</p>
<p>Variant can always casted back to the original record in the table specific code, exact process is described below.</p>
<h2 id=table-specific-code>Table specific code</h2>
<p>To do table-specific processing, it is necessary to get the RecordRef first, since NUMBER parameter will tell us which table it is. In the table-specific code, it is possible to cast the variant back to the original record type, so data is accessible and it is possible to invoke functions.</p>
<p>To do this, the best practice is to use the COPY function to preserve filters:</p>
<p>SalesHeader.COPY(RecordVariant);</p>
<p>Assigning directly such as SalesHeader := RecordVariant, is possible, however all filters will be lost.</p>
<p>Example of table specific code:</p>
<p>CASE RecordRef.NUMBER OF</p>
<p>DATABASE::&ldquo;Sales Header&rdquo;:</p>
<p>BEGIN</p>
<p>SalesHeader.COPY(RecordVariant);</p>
<p>SalesHeader.PrintDocument;</p>
<p>END;</p>
<p>DATABASE::&ldquo;Purchase Header&rdquo;:</p>
<p>BEGIN</p>
<p>PurchaseHeader.COPY(RecordVariant)</p>
<p>&mldr;</p>
<p>END;</p>
<p>&mldr;.</p>
<p>It is a good practice to try to avoid the table specific code if possible.</p>
<p>One of the issues with table specific code is that the CASE statement can easily explode when large number of records are supported.</p>
<p>There are two possible solutions:</p>
<ol>
<li>Move the calculations outside of the façade code unit and pass it in as part of the argument table.</li>
</ol>
<p>For example, instead of having a case like this within DocumentPrint codeunit:</p>
<p>CASE RecordRef.NUMBER OF</p>
<p>DATABASE::&ldquo;Sales Header&rdquo;:</p>
<p>BEGIN</p>
<p>SalesHeader.COPY(RecordVariant);</p>
<p>CASE SalesHeader.&ldquo;Document Type&rdquo; OF</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::Quote:</p>
<p>ReportSelections.SETRANGE(Usage,ReportSelections.Usage::&ldquo;S.Quote&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::&ldquo;Blanket Order&rdquo;:</p>
<p>ReportSelections.SETRANGE(Usage,ReportSelections.Usage::&ldquo;S.Blanket&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::Order:</p>
<p>ReportSelections.SETRANGE(Usage,ReportSelections.Usage::&ldquo;S.Order&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::&ldquo;Return Order&rdquo;:</p>
<p>ReportSelections.SETRANGE(Usage,ReportSelections.Usage::&ldquo;S.Return&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::Invoice:</p>
<p>ReportSelections.SETRANGE(Usage,ReportSelections.Usage::&ldquo;S.Invoice&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::&ldquo;Credit Memo&rdquo;:</p>
<p>ReportSelections.SETRANGE(Usage,ReportSelections.Usage::&ldquo;S.Cr.Memo&rdquo;);</p>
<p>END;</p>
<p>If the ReportSelections.Usage is simply passed into the function from outside, then the case statement is not needed at all. For example:</p>
<p>PrintDocumentArguments.&ldquo;Report Selection Usage&rdquo; := SalesHeader.GetReportSelectionUsage;</p>
<p>DocumentPrint.PrintDocument(SalesHeader,PrintDocumentArguments);</p>
<p>Where GetReportSelection usage is coded like this:</p>
<p>CASE SalesHeader.&ldquo;Document Type&rdquo; OF</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::Quote:</p>
<p>EXIT (ReportSelections.Usage::&ldquo;S.Quote&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::&ldquo;Blanket Order&rdquo;:</p>
<p>EXIT(ReportSelections.Usage::&ldquo;S.Blanket&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::Order:</p>
<p>EXIT(ReportSelections.Usage::&ldquo;S.Order&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::&ldquo;Return Order&rdquo;:</p>
<p>EXIT(ReportSelections.Usage::&ldquo;S.Return&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::Invoice:</p>
<p>EXIT(ReportSelections.Usage::&ldquo;S.Invoice&rdquo;);</p>
<p>SalesHeader.&ldquo;Document Type&rdquo;::&ldquo;Credit Memo&rdquo;:</p>
<p>EXIT(ReportSelections.Usage::&ldquo;S.Cr.Memo&rdquo;);</p>
<p>This way the code is much more reusable and simpler to read.</p>
<ol>
<li>Use Rules Table to replace the code with data-driven approach.</li>
</ol>
<p>Setup table would contain the list of the reports and their usages. Based on Table ID and usage it is possible to set filters on the setup table and run the object ID from the result.</p>
<p>For example:</p>
<p>ReportSelectionSetup.SETRANGE(&ldquo;Table ID&rdquo;, RecordRef.NUMBER);</p>
<p>ReportSelectionSetup.SETRANGE(&ldquo;Usage Type&rdquo;, RecordRef.FieldValue(ArgumentTable.&ldquo;Usage Type&rdquo;);</p>
<p>ReportSelectionSetup.FINDFIRST;</p>
<p>REPORT.RUN(ReportSelectionSetup.&ldquo;Report ID&rdquo;,VariantRecord);</p>
<hr>
<h1 id=example>Example</h1>
<p>The following code illustrates how the Variant Façade pattern can be used to implement the Document-Print Codeunit.</p>
<p><a href=Picture7.png><img src=Picture7.png alt=" "></a></p>
<p><a href=Picture8.png><img src=Picture8.png alt=" "></a></p>
<p>From the PrintDocument signature it is clear that it will not need to be changed in the future.</p>
<p>Code duplication is avoided, specific code is isolated in the PrepareRecord function, there is clear extension point to add support for new records in the future. Since code is not duplicated and there is a single flow through the method, inserting hooks and events in the future will be straightforward.</p>
<p>When adding the support for new records in most cases it is not need to change any code within the method, thus the cost of extending the usage is minimal.</p>
<p>Note - PrepareRecord function is placed for the illustrational purposes. An improvement would be to move all of the code from the PrepareRecord function before calling the function. So for the SalesHeader and PurchaseHeaders discounts should be calculated before invoking the function. For passing of the argument it should be one of the fields in the Argument Table, thus the entire specific code would be eliminated.</p>
<h1 id=consequences>Consequences</h1>
<ul>
<li>Not needed if the functionality needs to support few tables. Don&rsquo;t use it as a hammer</li>
<li>Strongly typing the records has it benefits since it is easier to find usages, errors will be visible at the compilation time.</li>
<li>Code becomes harder to debug within the variant façade</li>
<li>Be careful with filters and marks, if the function needs to support multiple records. Test these cases thoughtfully because with bad placement of code the filters can easily be lost.</li>
<li>Case statements can explode if there are too many tables that require specific processing. Then it is a must to find a way to keep the number of options in the CASE statement low. The Rules Table pattern and adding specifics to the Argument Table before invoking the code could help with keep the list shorter.</li>
</ul>
<h1 id=nav-usages>NAV usages</h1>
<ul>
<li>Codeunit 452 - Report Distribution Management</li>
<li>Codeunit 700 - Page Management</li>
<li>Codeunit 701 - Data Type Management</li>
<li>Codeunit 1268 - Export Launcher</li>
<li>Codeunit 1410 - Doc. Exch. Service Mgt.</li>
<li>Codeunit 1501 - Workflow Management</li>
<li>Codeunit 1521 - Workflow Response Handling</li>
<li>Codeunit 1531 - Workflow Change Rec Mgt.</li>
<li>Codeunit 1535 - Approvals Mgmt.</li>
</ul>
<h1 id=related-topics>Related Topics</h1>
<p>OO Facade <a href=https://en.wikipedia.org/wiki/Facade_pattern>https://en.wikipedia.org/wiki/Facade_pattern</a></p>
<p>Argument Table pattern - <a href=/nav/w/designpatterns/245.argument-table-pattern>https://community.dynamics.com/nav/w/designpatterns/245.argument-table-pattern</a></p>
<p>Rules Table pattern</p>
<p>&lt; &ndash;[if supportAnnotations]&ndash;>
&lt; &ndash;[endif]&ndash;></p>
<footer class=footline>
</footer>
</main>
</div>
<div id=navigation>
<a class="nav nav-prev" href=/navpatterns/1-patterns/transfer-custom-fields/ title="Transfer Custom Fields"><i class="fa fa-chevron-left"></i></a>
<a class="nav nav-next" href=/navpatterns/2-anti-patterns/ title="2. Anti-Patterns"><i class="fa fa-chevron-right"></i></a>
</div>
</div>
<div style=left:-1000px;overflow:scroll;position:absolute;top:-1000px;border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px>
<div style=border:none;box-sizing:content-box;height:200px;margin:0;padding:0;width:200px></div>
</div>
<script src=/js/clipboard.min.js?1639517494></script>
<script src=/js/perfect-scrollbar.min.js?1639517494></script>
<script src=/js/perfect-scrollbar.jquery.min.js?1639517494></script>
<script src=/js/jquery.svg.pan.zoom.js?1639517494></script>
<script src=/js/featherlight.min.js?1639517494></script>
<script src=/js/modernizr.custom-3.6.0.js?1639517494></script>
<script src=/js/relearn.js?1639517494></script>
</body>
</html>