{"id":283,"date":"2010-06-10T10:40:16","date_gmt":"2010-06-10T17:40:16","guid":{"rendered":"http:\/\/45.63.48.66\/?p=283"},"modified":"2010-07-07T17:36:26","modified_gmt":"2010-07-08T00:36:26","slug":"saving-filters-in-dynamics-nav-filter-selections-practical-usage-of-rec-getview-and-rec-setview","status":"publish","type":"post","link":"https:\/\/gotcal.com\/index.php\/2010\/06\/saving-filters-in-dynamics-nav-filter-selections-practical-usage-of-rec-getview-and-rec-setview\/","title":{"rendered":"Saving filters in Dynamics NAV &#8211; Filter Selections: Practical usage of Rec.GETVIEW and Rec.SETVIEW."},"content":{"rendered":"<p><img loading=\"lazy\" decoding=\"async\" class=\"alignright size-medium wp-image-305\" src=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/06\/filterspaper-300x300.jpg\" alt=\"\" width=\"300\" height=\"300\" srcset=\"https:\/\/gotcal.com\/wp-content\/uploads\/2010\/06\/filterspaper-300x300.jpg 300w, https:\/\/gotcal.com\/wp-content\/uploads\/2010\/06\/filterspaper-150x150.jpg 150w, https:\/\/gotcal.com\/wp-content\/uploads\/2010\/06\/filterspaper.jpg 500w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/>Over the years of working with NAV, users have always asked for ways to store their frequently used filters for reports and forms &#8211; eg. month end reports (A\/R, A\/P, Trial Balances), that often needs to be reported in multiple views.<br \/>\nMost often the users have come up with a system of storing the filterstrings in Notes in eg. Microsoft Outlook or similar. This is not a productive way, and leaves a lot of options for errors when copying the wrong filter, especially when filtering on multiple fields.<\/p>\n<p><!--more--><\/p>\n<p>Other ERP products, such as Great Pains has this option as standard, called &#8220;Report Options&#8221;. These can be setup and saved by the user, and then accessed through &#8220;My Reports&#8221;.<\/p>\n<p>In NAV we will implement the following functionality:<\/p>\n<ul>\n<li>allow users to store and retrieve table filters<span style=\"font-family: Times New Roman; font-size: 12pt;\"><br \/>\n<\/span><\/li>\n<li>allow setup per userid<\/li>\n<li>Allow editing of the filters the users created in a regular filter input in NAV<\/li>\n<li>having minimal impact on existing objects<\/li>\n<\/ul>\n<p>To design a similar feature in NAV, we need these new objects:<\/p>\n<ul>\n<li>1 table object<span style=\"font-family: Times New Roman; font-size: 12pt;\"><br \/>\n<\/span><\/li>\n<li>1 form object<\/li>\n<\/ul>\n<p>And also need to do changes to existing objects, where we want to make the functionality accessible. In this example we set up a single shortcut key on a existing menuitem with the shortcut ALT+F7, but you could also add buttons to the form, for loading and saving the filters, if this makes it easier for users to understand.<\/p>\n<p>First identify your next available table, that is accessible with your license (Available objects in my license). Create these fields in the new table:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/06\/061010_1740_FilterSelec1.png\" alt=\"\" \/><span style=\"font-family: Times New Roman; font-size: 12pt;\"><br \/>\n<\/span><\/p>\n<p>Most of the field should be pretty self explanatory for most developers; and you will see comments in the &#8220;Description&#8221; field explaining the properties set for the field.<\/p>\n<p>Remember to redefine the primary key on the table, as we want to allow each user to store multiple filters per table:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/06\/061010_1740_FilterSelec2.png\" alt=\"\" \/><span style=\"font-family: Times New Roman; font-size: 12pt;\"><br \/>\n<\/span><\/p>\n<p>If you have the granule <strong>7200 Application Builder<\/strong> on your license, you can also add this validation code for the Insert and Modify triggers:<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nOnInsert()\r\n&quot;Created On&quot; := TODAY;\r\n&quot;Created By&quot; := USERID;\r\n<\/pre>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\nOnModify()\r\n&quot;Modified On&quot; := TODAY;\r\n<\/pre>\n<p>Next step create our form to get and set the filters. For simplicity this could be created as 2 separate forms, but for now lets take a look at how to handle this in one form.<\/p>\n<p>Create a new form, based on the newly created table. Use the Form Wizard to built a &#8220;Tabular &#8211; Form Type&#8221; form. Add a Frame under the TableBox, to show the concatenated string for the tables view, something like this:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/06\/061010_1740_FilterSelec3.png\" alt=\"\" \/><span style=\"font-family: Times New Roman; font-size: 12pt;\"><br \/>\n<\/span><\/p>\n<p>Add to functions on the form, SetView() and GetView():<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nSetView(Filter : Text&#x5B;1000];TableID : Integer)\r\nGlobalFilter := Filter;\r\nIF STRPOS(Filter,'WHERE') = 0 THEN\r\n  EXIT;\r\nSETFILTER(&quot;User ID&quot;,USERID);\r\nSETRANGE(&quot;Table ID&quot;,TableID);\r\nSETRANGE(&quot;Filter Text 1&quot;,COPYSTR(Filter,1,250));\r\nSETRANGE(&quot;Filter Text 2&quot;,COPYSTR(Filter,251,250));\r\nSETRANGE(&quot;Filter Text 3&quot;,COPYSTR(Filter,501,250));\r\nSETRANGE(&quot;Filter Text 4&quot;,COPYSTR(Filter,751,250));\r\nIF FINDFIRST THEN BEGIN\r\n  MARK(TRUE);\r\n  SETRANGE(&quot;Filter Text 1&quot;);\r\n  SETRANGE(&quot;Filter Text 2&quot;);\r\n  SETRANGE(&quot;Filter Text 3&quot;);\r\n  SETRANGE(&quot;Filter Text 4&quot;);\r\nEND ELSE\r\n  SETFILTER(&quot;Filter Code&quot;,'&amp;lt;&amp;gt;%1','');\r\n<\/pre>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nGetView() : Text&#x5B;1000]\r\nEXIT(&quot;Filter Text 1&quot; + &quot;Filter Text 2&quot; + &quot;Filter Text 3&quot; + &quot;Filter Text 4&quot;);\r\n<\/pre>\n<p>And also this code<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nForm - OnOpenForm()\r\nMARKEDONLY(TRUE);\r\nIF FINDFIRST THEN;\r\nMARKEDONLY(FALSE);\r\n\r\nForm - OnNewRecord(BelowxRec : Boolean)\r\n&quot;Filter Text 1&quot; := COPYSTR(GlobalFilter,1,250);\r\n&quot;Filter Text 2&quot; := COPYSTR(GlobalFilter,251,250);\r\n&quot;Filter Text 3&quot; := COPYSTR(GlobalFilter,501,250);\r\n&quot;Filter Text 4&quot; := COPYSTR(GlobalFilter,751,250);\r\n<\/pre>\n<p>Lets put the objects to an test by implementing this on Form 21 Customer Card. Add another menu item to the Customer MenuButton, call it &#8220;Filter Selections&#8221; and assign it the shortcut key &#8220;Alt+F7&#8221;:<\/p>\n<p><img decoding=\"async\" src=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/06\/061010_1740_FilterSelec4.png\" alt=\"\" \/><span style=\"font-family: Times New Roman; font-size: 12pt;\"><br \/>\n<\/span><\/p>\n<p>The code should be this:<\/p>\n<pre class=\"brush: plain; title: ; notranslate\" title=\"\">\r\nFilterSelection.SetView(Rec.GETVIEW,DATABASE::Customer);\r\nFilterSelection.RUNMODAL;\r\nSETVIEW(FilterSelection.GetView);\r\n<\/pre>\n<p>Where FilterSelection is local variable to the previous form we created.<\/p>\n<p style=\"text-align: left;\">Lets testdrive it now, see this screencast recording: (notice you can also use the saved filters from your reports by selecting the arrow button on the request form, and have the functionality on your list form):<br \/>\n<a href=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/06\/reqform.png\" rel=\"lightbox[283]\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-full wp-image-290\" title=\"reqform\" src=\"http:\/\/45.63.48.66\/wp-content\/uploads\/2010\/06\/reqform.png\" alt=\"\" width=\"390\" height=\"258\" srcset=\"https:\/\/gotcal.com\/wp-content\/uploads\/2010\/06\/reqform.png 390w, https:\/\/gotcal.com\/wp-content\/uploads\/2010\/06\/reqform-300x198.png 300w\" sizes=\"auto, (max-width: 390px) 100vw, 390px\" \/><\/a><\/p>\n<p><script src=\"\/inc\/scripts\/common.js\" type=\"text\/javascript\"><\/script><\/p>\n<div id=\"container\">\n<form id=\"aspnetForm\" action=\"viewpage.aspx?mediaSetId=6cbaca69-170c-4727-98d2-1a2d07930ca5&amp;mediaGroupName=Jing&amp;findUserName=SNielsen\" method=\"post\">\n<div style=\"width: 100%;\">\n<div id=\"ctl00_mainContentPlaceholder_navigationLinks\" style=\"padding: 1px; margin: 2px auto 1px; width: 160px; height: 19px; font-size: 0.9em; color: #666666; border: 1px solid #d7d7d7; background: url(\/img\/view\/pgnn-container-bg.gif) repeat-x scroll 0% 0% white; display: none;\">\n<div id=\"ctl00_mainContentPlaceholder_resizeArea\" style=\"float: left; font-size: 0.8em; font-weight: bold; text-align: center;\"><a id=\"resizeLink\" class=\"highlightable\" style=\"color: #666; text-decoration: none;\" title=\"View original size\" href=\"javascript:toggleResizing();\"><\/a><br \/>\n\u00a0<\/p>\n<p><a id=\"resizeLink\" class=\"highlightable\" style=\"color: #666; text-decoration: none;\" title=\"View original size\" href=\"javascript:toggleResizing();\"> <img decoding=\"async\" id=\"scaleImage\" style=\"vertical-align: middle; padding: 1px 0 0 1px;\" src=\"\/img\/view\/zoom-in.gif\" alt=\"view original size\" \/><br \/>\n <span id=\"resizeText\" style=\"vertical-align: middle;\">full size<\/span> <\/a>\n<\/div>\n<\/div>\n<\/div>\n<table id=\"mediaTable\" border=\"0\" width=\"100%\">\n<tbody>\n<tr align=\"center\">\n<td style=\"border: 0px; padding: 0;\">\n<div id=\"mediaDisplayArea\" style=\"margin-top: 2px;\"><object id=\"scPlayer\" classid=\"clsid:d27cdb6e-ae6d-11cf-96b8-444553540000\" width=\"600\" height=\"450\" codebase=\"http:\/\/download.macromedia.com\/pub\/shockwave\/cabs\/flash\/swflash.cab#version=6,0,40,0\"><param name=\"quality\" value=\"high\" \/><param name=\"bgcolor\" value=\"#FFFFFF\" \/><param name=\"flashVars\" value=\"thumb=http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/FirstFrame.jpg&amp;containerwidth=600&amp;containerheight=450&amp;advseek=true&amp;content=http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/Filter_Selections_on_Customer_Card.mp4&amp;blurover=false\" \/><param name=\"allowFullScreen\" value=\"true\" \/><param name=\"scale\" value=\"showall\" \/><param name=\"allowScriptAccess\" value=\"always\" \/><param name=\"base\" value=\"http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/\" \/><param name=\"src\" value=\"http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/jingh264player.swf\" \/><param name=\"flashvars\" value=\"thumb=http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/FirstFrame.jpg&amp;containerwidth=600&amp;containerheight=450&amp;advseek=true&amp;content=http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/Filter_Selections_on_Customer_Card.mp4&amp;blurover=false\" \/><param name=\"allowfullscreen\" value=\"true\" \/><embed id=\"scPlayer\" type=\"application\/x-shockwave-flash\" width=\"600\" height=\"450\" src=\"http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/jingh264player.swf\" base=\"http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/\" allowscriptaccess=\"always\" scale=\"showall\" allowfullscreen=\"true\" flashvars=\"thumb=http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/FirstFrame.jpg&amp;containerwidth=600&amp;containerheight=450&amp;advseek=true&amp;content=http:\/\/content.screencast.com\/users\/SNielsen\/folders\/Jing\/media\/6cbaca69-170c-4727-98d2-1a2d07930ca5\/Filter_Selections_on_Customer_Card.mp4&amp;blurover=false\" bgcolor=\"#FFFFFF\" quality=\"high\"><\/embed><\/object><\/div>\n<\/td>\n<\/tr>\n<tr align=\"center\">\n<td style=\"text-align: left;\">[dm]4[\/dm]<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><!-- Hidden controls used for folder \/ item actions. --><br \/>\n <input id=\"ctl00_mainContentPlaceholder_action_mediaSetId\" name=\"ctl00$mainContentPlaceholder$action_mediaSetId\" type=\"hidden\" \/> <input id=\"ctl00_mainContentPlaceholder_action_mediaGroupId\" name=\"ctl00$mainContentPlaceholder$action_mediaGroupId\" type=\"hidden\" \/> <script type=\"text\/javascript\">\/\/ <![CDATA[\n       CSOnLoad();       if ( typeof resizeEvent == \"function\" )       {          resizeEvent();       }\n\/\/ ]]><\/script><\/p>\n<p><!-- TemplateId:  8 --><\/p>\n<p><script type=\"text\/javascript\">\/\/ <![CDATA[\n  Sys.Application.initialize();\n\/\/ ]]><\/script><\/p>\n<\/form>\n<\/div>\n<!-- AddThis Advanced Settings generic via filter on the_content --><!-- AddThis Share Buttons generic via filter on the_content -->","protected":false},"excerpt":{"rendered":"<p>Over the years of working with NAV, users have always asked for ways to store their frequently used filters for reports and forms &#8211; eg. month end reports (A\/R, A\/P, Trial Balances), that often needs to be reported in multiple views. Most often the users have come up with a system of storing the filterstrings [&hellip;]<!-- AddThis Advanced Settings generic via filter on get_the_excerpt --><!-- AddThis Share Buttons generic via filter on get_the_excerpt --><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[3],"tags":[77,26,7],"class_list":["post-283","post","type-post","status-publish","format-standard","hentry","category-navision","tag-navision","tag-filter","tag-objects"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/283","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/comments?post=283"}],"version-history":[{"count":23,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions"}],"predecessor-version":[{"id":302,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/posts\/283\/revisions\/302"}],"wp:attachment":[{"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/media?parent=283"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/categories?post=283"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/gotcal.com\/index.php\/wp-json\/wp\/v2\/tags?post=283"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}