{"id":1675,"date":"2015-08-26T18:07:27","date_gmt":"2015-08-26T12:37:27","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=1675"},"modified":"2026-02-05T15:43:09","modified_gmt":"2026-02-05T10:13:09","slug":"set-address-using-lookup-address-for-locked-address-fields-in-dynamics-crm","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2015\/08\/set-address-using-lookup-address-for-locked-address-fields-in-dynamics-crm\/","title":{"rendered":"Set Address using Lookup Address for locked Address fields in Dynamics CRM"},"content":{"rendered":"<p>Recently, we had a request, the request is like this, Bill-To address and Ship-To address on the Quote would be locked fields.<\/p>\n<p>This means, one way of setting the Bill-To and Ship-To is by using Lookup Address button.<\/p>\n<p>So, initially we thought it would be a Cakewalk.<\/p>\n<p>We wrote a script and called it on load to lock the Ship-To and Bill-To fields.<\/p>\n<p>Since, we wanted to show the fly-out, we didn`t lock the Main composite field and we locked the involved fields only.<\/p>\n<p>Now, as the fields were read-only, Lookup Address button did set the addresses, but it failed to save the value.<\/p>\n<p>In order to overcome this, we wrote another script on load of the form, to set the SetSubmitMode for all the address fields to always.<\/p>\n<p><strong>Script:<\/strong><\/p>\n<p>function setSubmitModeAlways() {<\/p>\n<p>var functionName = &#8220;setSubmitModeAlways&#8221;;<\/p>\n<p>var fields = new Array();<\/p>\n<p>try {<\/p>\n<p>fields = [&#8220;shipto_line1&#8221;, &#8220;shipto_line2&#8221;, &#8220;shipto_line3&#8221;, &#8220;shipto_postalcode&#8221;, &#8220;shipto_stateorprovince&#8221;, &#8220;shipto_city&#8221;, &#8220;shipto_country&#8221;, &#8220;billto_line1&#8221;, &#8220;billto_line2&#8221;, &#8220;billto_line3&#8221;, &#8220;billto_postalcode&#8221;, &#8220;billto_stateorprovince&#8221;, &#8220;billto_city&#8221;, &#8220;billto_country&#8221;];<\/p>\n<p>$.each(fields, function (index, item) {<\/p>\n<p>if (Xrm.Page.getAttribute(item)) {<\/p>\n<p>Xrm.Page.getAttribute(item).setSubmitMode(&#8220;always&#8221;);<\/p>\n<p>}<\/p>\n<p>});<\/p>\n<p>} catch (e) {<\/p>\n<p>throwError(e, functionName);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>We thought this should be enough and it did feel initially, that we are through.<\/p>\n<p>But, later in testing phase, we came across an issue, the issue is as below.<\/p>\n<p>After creating a Quote, we used the Lookup Address button to get the addresses and it worked like a charm.<\/p>\n<p>The data is stored as below and the field on the fly-out is read-only.<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/08\/address_field1.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1677\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/08\/address_field1.png\" alt=\"address_field1\" width=\"628\" height=\"245\" \/><\/a><\/p>\n<p>Now, we changed both the addresses using the Lookup Address button.<\/p>\n<p>On save, the addresses, got saved, but the composite fields still showed old address.<a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/08\/address_field2.png\"><img decoding=\"async\" class=\"aligncenter size-full wp-image-1678\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/08\/address_field2.png\" alt=\"address_field2\" width=\"302\" height=\"186\" \/><\/a><\/p>\n<p>After few hours of scratching our head, we thought of changing our approach.<\/p>\n<p>We came up with the plan of skipping setSubmitModeAlways function and using another approach.<\/p>\n<p>Our new approach, made the fields read-only and it didn`t involve using the SetSubmitMode either.<\/p>\n<p>We removed the onload SetSubmitModeAlways.<\/p>\n<p>The last part of this approach was calling the setFieldReadOnly function on save as well.<\/p>\n<p>setFieldReadOnly is a function wrote by us to disable address fields.<\/p>\n<p>\/\/Function called onSave of the form<\/p>\n<p>function onSave_Form() {<\/p>\n<p>var functionName = &#8220;onSave_Form&#8221;;<\/p>\n<p>try {<\/p>\n<p>\/\/Enabled fields<\/p>\n<p>setFieldReadOnly(false);<\/p>\n<p>\/\/Call the Timeout function<\/p>\n<p>setTimeout(function () {<\/p>\n<p>\/\/Disabled fields<\/p>\n<p>setFieldReadOnly(true);<\/p>\n<p>}, 2000);<\/p>\n<p>} catch (e) {<\/p>\n<p>throwError(e, functionName);<\/p>\n<p>}<\/p>\n<p>}<\/p>\n<p>You would be confused, why did we enabled the fields and then disabled them again.<\/p>\n<p>We enabled all the address fields, because, by making a field editable it is saved without using the SetSubmitMode.<\/p>\n<p>We disabled it after 2 seconds of save using SetTimeout function because we wanted the fields read-only and we didn`t want it to be read-only before save, otherwise it would have incurred the same issue that we tackled using the above approach.<\/p>\n<p><strong><em>Note:<\/em><\/strong><\/p>\n<p><em>This issue seems to be fixed in CRM 2015 update 1, but this is very much there in CRM 2013 through CRM 2015.<\/em><\/p>\n<p>Its just not this, before moving further, check out our new utility tool\u00a0<a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/user-adoption-monitor-in-dynamics-crm\/\" target=\"_blank\" rel=\"noopener noreferrer\">User Adoption Tracker<\/a>. Monitor what your teams are actually doing in\u00a0Dynamics CRM. Email us on\u00a0<a href=\"mailto:crm@inogic.com\">crm@inogic.com<\/a>\u00a0for a trial or if you would like to see a live demo.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Recently, we had a request, the request is like this, Bill-To address and Ship-To address on the Quote would be locked fields. This means, one way of setting the Bill-To and Ship-To is by using Lookup Address button. So, initially we thought it would be a Cakewalk. We wrote a script and called it on\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2015\/08\/set-address-using-lookup-address-for-locked-address-fields-in-dynamics-crm\/\">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":[15,19,22,23,24,33],"tags":[592],"class_list":["post-1675","post","type-post","status-publish","format-standard","hentry","category-development","category-dynamics-crm","category-dynamics-crm-2015","category-dynamics-crm-2015-update-1","category-dynamics-crm-2016","category-javascript","tag-dynamics-crm"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/1675","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=1675"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/1675\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=1675"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=1675"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=1675"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}