{"id":367,"date":"2023-02-24T01:35:00","date_gmt":"2023-02-24T01:35:00","guid":{"rendered":"https:\/\/automatethemundane.com\/index.php\/2023\/02\/24\/expanding-model-driven-apps-with-code-hiding-tabs-based-on-value\/"},"modified":"2023-07-04T14:33:36","modified_gmt":"2023-07-04T14:33:36","slug":"expanding-model-driven-apps-with-code-hiding-tabs-based-on-value","status":"publish","type":"post","link":"https:\/\/automatethemundane.com\/index.php\/2023\/02\/24\/expanding-model-driven-apps-with-code-hiding-tabs-based-on-value\/","title":{"rendered":"Expanding Model Driven apps with code- Hiding Tabs based on value"},"content":{"rendered":"\n<p class=\"has-text-color\" style=\"color:rgba(120, 119, 116, 1)\">2\/24\/2023<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity is-style-wide\"\/>\n\n\n\n<h1 class=\"wp-block-heading\">The Why<\/h1>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Using Java code in a Model Driven app offers several benefits. One major advantage is the ability to extend the app's functionality beyond what is available out-of-the-box. Java code can be used to create custom components, integrate with other systems, and perform complex calculations and data processing tasks. Additionally, Java is a widely-used language with a large community of developers, which means that there are many resources available for those looking to learn or troubleshoot issues.<\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">In this first part, we will expand our model-driven app to hide unnecessary tabs. During the design phase <a href=\"https:\/\/automatethemundane.com\/index.php\/2023\/02\/06\/building-a-model-driven-app-part-1-design\/\" target=\"_blank\" rel=\"noreferrer noopener\">Building a Model Driven App Part 1-Design<\/a>, we determined that requests below or equal to $100 did not require higher approval. Thus, we will hide the Higher Approval tab when the cost is less than or equal to $100.<\/p>\n\n\n\n<h1 class=\"wp-block-heading\">The How<\/h1>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Step one will be to write out some base JavaScript, then add in the actual fields. <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function FUNCTIONNAME(executionContext) {\n    var formContext = executionContext.getFormContext(); \/\/ get formContext\n    if(formContext.getAttribute(\"columnname\").getValue() = \"value\") {\n        \/\/if the value dose not match set the visibilty to false\n        formContext.ui.tabs.get(\"tabname\").setVisible(false);\n    }\n    else {\n        \/\/if the value dose match set the visibilty to true\n        formContext.ui.tabs.get(\"tabname\").setVisible(true);\n    }\n }<\/code><\/pre>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">The next step will be to set the function name, get the column name, the value we want, and the tab name. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Function Name<\/h2>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">The name for this function will be \u201cCost\u201d<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function Cost(executionContext) {\n    var formContext = executionContext.getFormContext(); \/\/ get formContext<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Column Name<\/h2>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Select the Table<\/li>\n\n\n\n<li>Select Columns<\/li>\n\n\n\n<li>Select the Cost Column<\/li>\n\n\n\n<li>Copy the Logical Name<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-11-1024x424.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>if(formContext.getAttribute(\"eddev_cost\")<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Value<\/h2>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">The Value we will be looking up is \u2264 $100<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>.getValue() &lt;= 100)<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Tab Name<\/h2>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">From the form find the tab to be hidden and copy its Name. Paste the Name into the code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-12-1024x283.png\" alt=\"\"\/><\/figure>\n\n\n\n<pre class=\"wp-block-code\"><code>if (formContext.getAttribute(\"eddev_cost\").getValue() &lt;= 100) {\n        \/\/if the value dose not match set the visibilty to false\n        formContext.ui.tabs.get(\"tab_higherapproval\").setVisible(false);\n    }\n    else {\n        \/\/if the value dose match set the visibilty to true\n        formContext.ui.tabs.get(\"tab_higherapproval\").setVisible(true);<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Entire code Block<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>function Cost(executionContext) {\n    var formContext = executionContext.getFormContext(); \/\/ get formContext\n    if (formContext.getAttribute(\"eddev_cost\").getValue() &lt;= 100) {\n        \/\/if the value dose not match set the visibilty to false\n        formContext.ui.tabs.get(\"tab_higherapproval\").setVisible(false);\n    }\n    else {\n        \/\/if the value dose match set the visibilty to true\n        formContext.ui.tabs.get(\"tab_higherapproval\").setVisible(true);\n    }\n }<\/code><\/pre>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Save the code block with a .js as its extension. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-13.png\" alt=\"\"\/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Apply the code<\/h2>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">From the solutions menu add a new web resource<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-14.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Upload the file and give it a Display name along with a Name<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-15.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Back on the Form Select Add Library<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-16-1024x404.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Add the web resource from above. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-17.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">From the main form Select Events, On Load, Event Handler. <\/p>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Enter in the Function name declared in the code.<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-18.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">From the Input Tab Select Cost, Select Events, Event Handler, enter in the function name declared above. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-19-1024x381.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Select the Higher Approval Tab and select Hide. This is done to ensure that the tab is only seen when it is needed to. <\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img decoding=\"async\" src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/image-20-1024x522.png\" alt=\"\"\/><\/figure>\n\n\n\n<p class=\"has-text-color\" style=\"color:rgb(0, 0, 0)\">Save and Publish all changes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Testing<\/h2>\n\n\n\n<figure class=\"wp-block-video\"><video height=\"1080\" style=\"aspect-ratio: 1920 \/ 1080;\" width=\"1920\" controls src=\"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/video-1.mp4\"><\/video><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>2\/24\/2023 The Why Using Java code in a Model Driven app offers several benefits. One major advantage is the ability to extend the app&#8217;s functionality beyond what is available out-of-the-box. Java code can be used to create custom components, integrate with other systems, and perform complex calculations and data processing tasks. Additionally, Java is a [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":140,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[31,39,4],"class_list":["post-367","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-model-driven-app","tag-forms","tag-javascript","tag-mda","entry","has-media"],"jetpack_featured_media_url":"https:\/\/automatethemundane.com\/wp-content\/uploads\/2023\/05\/cover-13-scaled.jpg","_links":{"self":[{"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/posts\/367","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/comments?post=367"}],"version-history":[{"count":3,"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/posts\/367\/revisions"}],"predecessor-version":[{"id":497,"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/posts\/367\/revisions\/497"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/media\/140"}],"wp:attachment":[{"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/media?parent=367"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/categories?post=367"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/automatethemundane.com\/index.php\/wp-json\/wp\/v2\/tags?post=367"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}