{"id":2166,"date":"2015-12-28T15:52:00","date_gmt":"2015-12-28T10:22:00","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=2166"},"modified":"2021-08-25T11:13:13","modified_gmt":"2021-08-25T11:13:13","slug":"identify-dirty-fields-on-microsoft-dynamics-crm-form","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2015\/12\/identify-dirty-fields-on-microsoft-dynamics-crm-form\/","title":{"rendered":"Identify \u201cDirty\u201d fields on Microsoft Dynamics CRM form"},"content":{"rendered":"<p><b><span style=\"text-decoration: underline;\">Introduction:<\/span><\/b><\/p>\n<p>There may be times when you want to identify the fields that have been modified by the user in the current update.<\/p>\n<p>While one way and the most common way has been to create a Plugin, the plugin only receives data of the fields that have been modified in the current update. If you wanted to check the previous value, you could compare the PreImage with the current value in the target and if they don\u2019t match, it has been modified.<\/p>\n<p><b><span style=\"text-decoration: underline;\">What if we had to identify the modified field through scripting?<\/span><\/b><\/p>\n<p>It is common knowledge the form provides an IsDirty property that can be used to check if the form has been modified. We can check the form IsDirty using<\/p>\n<p><code>Xrm.Page.data.entity.getIsDirty()<\/code><\/p>\n<p>To get the list of attributes that have been modified in this session, you can check the IsDirty of the attribute. Here is a sample code of how you can loop through all the attributes and get the list of the modified attributes on the form<\/p>\n<div id=\"scid:9D7513F9-C04C-4721-824A-2B34F0212519:bcf3a124-6440-4fa9-a406-05e7727e9ace\" class=\"wlWriterEditableSmartContent\" style=\"float: none; margin: 0px; display: inline; padding: 0px;\">\n<div>\n<pre class=\"lang:default decode:true\">\/\/get list of dirty fields\r\n        oppAttributes = Xrm.Page.data.entity.attributes.get();\r\n\r\n        if (oppAttributes != null) {\r\n            for (var i in oppAttributes) {\r\n                if (oppAttributes[i].getIsDirty()) {\r\n                    listofDirtyAttri += oppAttributes[i].getName() + \"\\n\";\r\n                }\r\n            }\r\n        }<\/pre>\n<p>Another function that comes in handy here is <code>Xrm.Page.data.entity.getDataXml()<\/code><\/p>\n<\/div>\n<\/div>\n<div id=\"scid:9D7513F9-C04C-4721-824A-2B34F0212519:a064114a-daa3-425b-a92a-12fd865ffc1c\" class=\"wlWriterEditableSmartContent\" style=\"float: none; margin: 0px; display: inline; padding: 0px;\">\n<div><!--\n\nCode highlighting produced by Actipro CodeHighlighter (freeware)\nhttp:\/\/www.CodeHighlighter.com\/\n\n--><span style=\"color: #0000ff;\">var<\/span><span style=\"color: #000000;\"> dataXml <\/span><span style=\"color: #000000;\">=<\/span><span style=\"color: #000000;\"> Xrm.Page.data.entity.getDataXml();<\/span><\/div>\n<p><!-- Code inserted with Steve Dunn's Windows Live Writer Code Formatter Plugin.  http:\/\/dunnhq.com --><\/p>\n<\/div>\n<p>the result would be<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/12\/dataXml.png\"><img decoding=\"async\" class=\"alignnone\" style=\"background-image: none; padding-top: 0px; padding-left: 0px; display: inline; padding-right: 0px; border: 0px;\" title=\"dataXml\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2015\/12\/dataXml_thumb.png\" alt=\"Identify Dirty fields on Microsoft Dynamics CRM form\" width=\"641\" height=\"326\" border=\"0\" \/><\/a><\/p>\n<p>Using the above function you can get a list of the data that is passed to the platform on update, and this inturn lists all the attributes that have been modified along with the current values being sent to the platform.<\/p>\n<p><b><span style=\"text-decoration: underline;\">Conclusion:<\/span><\/b><\/p>\n<p>Combination of getIsDirty on the form\/attribute and getDataXml would help you quickly build a tracking tool without the need for a plugin.<\/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\">Free 70% of storage space in CRM with Attachment Management Apps!<\/div><\/div><\/h2>\n<p><em><strong><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/attach-2-dynamics-365-crm-upload-multiple-files-sharepoint-cloud-storage\" target=\"_blank\" rel=\"noopener noreferrer\">Attach2Dynamics<\/a> &#8211; Store and manage documents\/attachments in cloud storage of your choice &#8211; SharePoint, Dropbox or Azure Blob Storage from within Dynamics 365 CRM.<\/em><br \/>\n<em><strong><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/dynamics-365-crm-sharepoint-security-metadata-sync\" target=\"_blank\" rel=\"noopener noreferrer\">SharePoint Security Sync<\/a><\/strong> \u2013 Robust and secure solution to integrate Dynamics 365 CRM and SharePoint Security Sync thereby ensuring secure access to confidential documents stored in SharePoint.<\/em><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: There may be times when you want to identify the fields that have been modified by the user in the current update. While one way and the most common way has been to create a Plugin, the plugin only receives data of the fields that have been modified in the current update. If you\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2015\/12\/identify-dirty-fields-on-microsoft-dynamics-crm-form\/\">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,33],"tags":[509],"class_list":["post-2166","post","type-post","status-publish","format-standard","hentry","category-development","category-dynamics-crm","category-javascript","tag-dirty-fields"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2166","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=2166"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/2166\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=2166"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=2166"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=2166"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}