{"id":21939,"date":"2020-01-08T12:02:00","date_gmt":"2020-01-08T12:02:00","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=21939"},"modified":"2022-09-02T15:55:06","modified_gmt":"2022-09-02T10:25:06","slug":"do-we-still-need-to-use-setsubmitmode-to-save-the-value-of-a-read-only-attribute","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2020\/01\/do-we-still-need-to-use-setsubmitmode-to-save-the-value-of-a-read-only-attribute\/","title":{"rendered":"Do we still need to use setSubmitMode to save the value of a read-only attribute?"},"content":{"rendered":"<p><strong>Introduction:<\/strong><\/p>\n<p style=\"text-align: justify;\">Before we get to the answer to this question, first we will see what the use of setSubmitMode is. The <a href=\"https:\/\/docs.microsoft.com\/en-us\/powerapps\/developer\/model-driven-apps\/clientapi\/reference\/attributes\/setsubmitmode\">setSubmitMode<\/a> is a method to set whether data from the attribute will be submitted when the record is saved.<\/p>\n<p>This method accepts one of the below values as a parameter;<\/p>\n<ul>\n<li><strong>Always:<\/strong> If we set as <strong>\u2018\u2019always\u2019\u2019<\/strong> then data of the attribute will always be sent with a save. Data will be saved always even though the attribute is not dirty.<\/li>\n<li><strong>Never:<\/strong> If we set as <strong>\u2018\u2019never\u2019\u2019<\/strong> then data of the attribute will never be sent with a save. Data will not be saved even when value\/data of the field is changed. We use this mode when we don\u2019t want to capture the value but want to trigger some logic on change of the attribute.<\/li>\n<li><strong>Dirty:<\/strong> This mode will send the data with a save or when it has been changed.<\/li>\n<\/ul>\n<p style=\"text-align: justify;\">If we ask any CRM developer what is the use of setSubmitMode method along with the aforementioned details we will get one more answer i.e. we have to use setSubmitMode with <strong>\u2018\u2019always\u2019\u2019<\/strong> to save the value of read-only attribute. If we have a read-only attribute on the form and want to set the value through script then we would need to write an additional line of code i.e. setSubmitMode with <strong>\u2018\u2019always\u2019\u2019<\/strong> parameter.<\/p>\n<pre>Xrm.Page.getAttribute(\"new_availablecredit\").setValue(2000);\r\n\r\nXrm.Page.getAttribute(\"new_availablecredit\").setSubmitMode(\"always\");<\/pre>\n<p style=\"text-align: justify;\">But this have been changed from Dynamics 365 9.x version. Now, we don\u2019t need to use this additional line of code to send the value of the read-only attribute. This is explained in the below link where you can see we are copying the value of <strong>\u201cCredit\u201d<\/strong> attribute to read-only <strong>\u201cAvailable Credit\u201d<\/strong> attribute.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-21957\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2020\/01\/Demo.gif\" alt=\"\" width=\"800\" height=\"450\" \/><\/p>\n<p>And the below code is used on change of <strong>\u201cCredit\u201d<\/strong> attribute:<\/p>\n<pre>function\u00a0calculateCredit(context)\u00a0{\r\n\r\n\u00a0\u00a0\u00a0\u00a0try\u00a0{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var\u00a0formContext\u00a0=\u00a0context.getFormContext();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0var\u00a0credit\u00a0=\u00a0formContext.getAttribute(\"creditlimit\").getValue();\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0formContext.getAttribute(\"new_availablecredit\").setValue(credit);\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\r\n\r\n\u00a0\u00a0\u00a0\u00a0}\u00a0catch\u00a0(error)\u00a0{\r\n\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0throw\u00a0new\u00a0Error(error.message);\r\n\r\n\u00a0\u00a0\u00a0\u00a0}\r\n\r\n}<\/pre>\n<p><strong>Conclusion:<\/strong><\/p>\n<p style=\"text-align: justify;\">So basically, the value of the read-only field can be saved without writing an additional setSubmitMode method. Moreover, this also works in both classic web and Unified interface.<\/p>\n<h2 style=\"text-align: left;\"><div class=\"su-heading su-heading-style-default su-heading-align-center\" id=\"\" style=\"font-size:15px;margin-bottom:5px\"><div class=\"su-heading-inner\">Generate Your Own New Leads Within Microsoft Dynamics 365 CRM<\/div><\/div><\/h2>\n<p><em>Contact us for a <a href=\"https:\/\/www.maplytics.com\/maplytics-download\/?utm_source=highvisits&amp;utm_medium=technicalblog&amp;utm_campaign=hMaplytics\" target=\"_blank\" rel=\"noopener\">demo<\/a> to know more about how <a href=\"https:\/\/www.maplytics.com\/?utm_source=highvisits&amp;utm_medium=technicalblog&amp;utm_campaign=hMaplytics\" target=\"_blank\" rel=\"noopener\">Maplytics<\/a> can help you to generate new leads from within Microsoft Dynamics 365 CRM.<\/em><\/p>\n<p><em><a href=\"https:\/\/www.maplytics.com\/?utm_source=highvisits&amp;utm_medium=technicalblog&amp;utm_campaign=hMaplytics\" target=\"_blank\" rel=\"noopener\">Maplytics<\/a> is a 5-star rated, preferred business app on the <a href=\"https:\/\/appsource.microsoft.com\/en-us\/product\/dynamics-365\/inogic.f6f3c73f-29de-4fa8-a396-87ea8a07b6c4?tab=Overview\" target=\"_blank\" rel=\"noopener\">Microsoft AppSource<\/a> that is Certified for Microsoft Dynamics 365 (CfMD) and comes with powerful features like Appointment Planning, Sales Routing, Territory Management, Heat Maps, Geo-analytical Dashboards and more that empower organizations to add more value to their CRM data, improve sales &amp; service processes, and achieve high ROI.<\/em><\/p>\n<p><em>Get your <a href=\"https:\/\/www.maplytics.com\/maplytics-download\/?utm_source=highvisits&amp;utm_medium=technicalblog&amp;utm_campaign=hMaplytics\" target=\"_blank\" rel=\"noopener\">free trial<\/a> from our Website or <a href=\"https:\/\/appsource.microsoft.com\/en-us\/product\/dynamics-365\/inogic.f6f3c73f-29de-4fa8-a396-87ea8a07b6c4?tab=Overview\" target=\"_blank\" rel=\"noopener\">Microsoft AppSource<\/a>!<\/em><\/p>\n<p><em>&#8216;If data is the new oil, location intelligence is ??\u201d<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: Before we get to the answer to this question, first we will see what the use of setSubmitMode is. The setSubmitMode is a method to set whether data from the attribute will be submitted when the record is saved. This method accepts one of the below values as a parameter; Always: If we set\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2020\/01\/do-we-still-need-to-use-setsubmitmode-to-save-the-value-of-a-read-only-attribute\/\">Read More &raquo;<\/a><\/span><\/p>\n","protected":false},"author":13,"featured_media":21973,"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":[16],"tags":[533,1993,1992],"class_list":["post-21939","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dynamics-365","tag-dynamics-365","tag-read-only-attributes","tag-setsubmitmode"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/21939","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=21939"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/21939\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media\/21973"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=21939"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=21939"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=21939"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}