{"id":28741,"date":"2021-07-26T12:11:08","date_gmt":"2021-07-26T12:11:08","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=28741"},"modified":"2023-09-08T12:59:13","modified_gmt":"2023-09-08T07:29:13","slug":"how-to-convert-an-editable-basic-form-entity-form-to-read-mode-programmatically-in-power-apps-portal","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2021\/07\/how-to-convert-an-editable-basic-form-entity-form-to-read-mode-programmatically-in-power-apps-portal\/","title":{"rendered":"How to convert an editable Basic Form (Entity Form) to read mode programmatically in Power Apps Portal"},"content":{"rendered":"<h2 style=\"text-align: justify;\"><strong>Introduction:<\/strong><\/h2>\n<p style=\"text-align: justify;\">We recently had a requirement in Power Apps Partner Portal where client wanted the basic form (entity form) of quote to be editable for quotes with most of the status reasons under status &#8220;Draft\u201d. But client also wanted to restrict users making any change to the quote from Portal for some status reasons even when quote is still in Draft status.<\/p>\n<p style=\"text-align: justify;\">Our initial approach was with some Portal script we would disable the \u201cSubmit\u201d button (here in our case, button is disabled for some specific status reasons of quotes under \u201cDraft\u201d status) so that even if user tries to enter data, it won\u2019t be reflected in CRM since Submit button is disabled. Given below is the line of code written in document ready function of the portal script of entity form:<\/p>\n<p style=\"text-align: justify;\"><strong>$(<\/strong><strong>&#8216;#UpdateButton&#8217;<\/strong><strong>).attr(<\/strong><strong>&#8220;disabled&#8221;<\/strong><strong>, <\/strong><strong>true<\/strong><strong>);<\/strong><\/p>\n<p style=\"text-align: justify;\">Though this was half serving the purpose, client did not want users to even attempt editing anything as they anyways won\u2019t be able to submit it. In short, client didn\u2019t want user to enter the data at all even though the submit button was disabled.<\/p>\n<p style=\"text-align: justify;\">So, we thought along with \u201cSubmit\u201d button we would also make fields read only whenever Submit button is disabled. But the problem was that in future there would be chances of adding new fields or removing new fields. And every time such change would come, we would have to edit our entity form script in Portal to accommodate the same. Hence, such solution which needs constant editing was not considered.<\/p>\n<p style=\"text-align: justify;\">Now, we were trying to find out what\u2019s the best approach with generic coding that can make an entity form in edit mode behave as if the form is in \u201cread only\u201d mode. Hence after some research, we found that there is indeed a way where we can make any entity form which is in \u201cEdit\u201d mode to behave like an entity form in \u201cRead Only\u201d mode.<\/p>\n<p style=\"text-align: justify;\">Add the following code in the document ready function of the portal script present in the entity form (which is in \u201cEdit\u201d mode by default) as per the different conditions you will have where you might want to make the form read only programmatically.<\/p>\n<p style=\"text-align: justify;\"><strong>$(<\/strong><strong>&#8220;#EntityFormControl_EntityFormView&#8221;<\/strong><strong>).addClass(<\/strong><strong>&#8220;form-readonly&#8221;<\/strong><strong>);<\/strong><\/p>\n<p style=\"text-align: justify;\"><strong>$(<\/strong><strong>&#8220;#EntityFormControl_EntityFormView :input&#8221;<\/strong><strong>).attr(<\/strong><strong>&#8220;disabled&#8221;<\/strong><strong>, <\/strong><strong>true<\/strong><strong>);<\/strong><\/p>\n<p style=\"text-align: justify;\"><strong>$(<\/strong><strong>&#8216;#UpdateButton&#8217;<\/strong><strong>).attr(<\/strong><strong>&#8220;disabled&#8221;<\/strong><strong>, <\/strong><strong>true<\/strong><strong>);<\/strong><\/p>\n<p style=\"text-align: justify;\">Please note that the id of basic form control in my case was \u201c<strong>EntityFormControl_EntityFormView<\/strong>\u201d. If the above lines of code doesn\u2019t work for you, then probably the reason will be id of basic form control in your case will be different from mine. So before publishing above lines of code, do the following.<\/p>\n<ol style=\"text-align: justify;\">\n<li>Go to your portal and visit the page using that basic form where you are editing the basic form with above lines.<\/li>\n<li>Press the button \u201cF12\u201d on your keyboard.<\/li>\n<li>Then on the screen, try to find the word \u201centityformcontrol\u201d on the \u201cElements\u201d tab as shown below. And when you find a line like \u201c&lt;div id=\u201dEntityFormControl_&lt;sometext&gt;&gt; like highlighted below, that\u2019s your id of entityformcontrol.<\/li>\n<\/ol>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image001-ink-2.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"wp-image-28742 size-full aligncenter\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image001-ink-2.png\" alt=\"How to convert an editable Basic Form (Entity Form) to read mode programmatically in Power Apps Portal\" width=\"993\" height=\"535\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image001-ink-2.png 993w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image001-ink-2-300x162.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image001-ink-2-768x414.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image001-ink-2-660x356.png 660w\" sizes=\"(max-width: 993px) 100vw, 993px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Given below is the same code with new id (got from above screenshot) of basic form:<\/p>\n<p style=\"text-align: justify;\"><strong>$(&#8220;#EntityFormControl_1ba19e3d2fd1e51180dfc4346bac0574&#8221;).addClass(&#8220;form-readonly&#8221;);<\/strong><\/p>\n<p style=\"text-align: justify;\"><strong>$(&#8220;#EntityFormControl_1ba19e3d2fd1e51180dfc4346bac0574 :input&#8221;).attr(&#8220;disabled&#8221;, true);<\/strong><\/p>\n<p style=\"text-align: justify;\"><strong>$(&#8216;#UpdateButton&#8217;).attr(&#8220;disabled&#8221;, true);<\/strong><\/p>\n<p style=\"text-align: justify;\">The screenshot below shows the same:<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image003-ink-3.png\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"aligncenter wp-image-28744 size-full\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image003-ink-3.png\" alt=\"How to convert an editable Basic Form (Entity Form) to read mode programmatically in Power Apps Portal\" width=\"978\" height=\"384\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image003-ink-3.png 978w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image003-ink-3-300x118.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image003-ink-3-768x302.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/image003-ink-3-660x259.png 660w\" sizes=\"(max-width: 978px) 100vw, 978px\" \/><\/a><\/p>\n<p style=\"text-align: justify;\">Now publish the changes, clear the portal cache and you will see the page with basic form (edit mode) would behave like page with basic form in read only mode where ALL fields present in the form are NOT editable due to the two lines of code written for basic form (as shared above). Also the submit button would be disabled due to the 3<sup>rd<\/sup> line of code written above.<\/p>\n<p style=\"text-align: justify;\"><strong>Conclusion:<\/strong><\/p>\n<p style=\"text-align: justify;\">In this way, we can make an editable basic form behave like a non-editable basic form programmatically in Power Apps portal.<\/p>\n<p style=\"text-align: justify;\"><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/kanban-board-dynamics-365-crm\" target=\"_blank\" rel=\"noopener noreferrer\"><img decoding=\"async\" class=\"wp-image-28745 size-full aligncenter\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/kb-1.jpg\" alt=\"Kanban Board\" width=\"800\" height=\"200\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/kb-1.jpg 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/kb-1-300x75.jpg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/kb-1-768x192.jpg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2021\/07\/kb-1-660x165.jpg 660w\" sizes=\"(max-width: 800px) 100vw, 800px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: We recently had a requirement in Power Apps Partner Portal where client wanted the basic form (entity form) of quote to be editable for quotes with most of the status reasons under status &#8220;Draft\u201d. But client also wanted to restrict users making any change to the quote from Portal for some status reasons even\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2021\/07\/how-to-convert-an-editable-basic-form-entity-form-to-read-mode-programmatically-in-power-apps-portal\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":0,"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":[38,44,2763],"tags":[1170],"class_list":["post-28741","post","type-post","status-publish","format-standard","hentry","category-microsoft-powerapps","category-power-apps","category-power-pages","tag-microsoft-powerapps"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/28741","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=28741"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/28741\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=28741"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=28741"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=28741"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}