{"id":34359,"date":"2023-04-01T12:53:55","date_gmt":"2023-04-01T07:23:55","guid":{"rendered":"https:\/\/www.inogic.com\/blog\/?p=34359"},"modified":"2023-04-04T15:21:25","modified_gmt":"2023-04-04T09:51:25","slug":"programmatically-update-oob-messages-in-microsoft-dynamics-365-crm","status":"publish","type":"post","link":"https:\/\/www.inogic.com\/blog\/2023\/04\/programmatically-update-oob-messages-in-microsoft-dynamics-365-crm\/","title":{"rendered":"Programmatically update OOB messages in Microsoft Dynamics 365 CRM"},"content":{"rendered":"<p><strong>Introduction<\/strong>:<\/p>\n<p>In Microsoft Dynamics 365 CRM, the display string messages are those messages which are shown on the Forms, error Popups, etc. which provide appropriate information to the users. However, a user can modify a message as per the business case. To accomplish this, Microsoft now provides us with a feature where we can directly update messages from <a href=\"https:\/\/learn.microsoft.com\/en-us\/power-apps\/maker\/data-platform\/edit-system-entity-messages\" target=\"_blank\" rel=\"noopener\">Power Apps<\/a> or through code.<\/p>\n<p>In this blog, we will discuss how to programmatically update table display strings in Microsoft Dynamics 365 CRM.<\/p>\n<p>In the CRM all the default messages are stored in one OOB entity called <strong>Display String<\/strong>. The Display String entity has two main text type attributes which are <strong>CustomDisplayString<\/strong> and <strong>PublishedDisplayString<\/strong>.<\/p>\n<ul>\n<li><strong>CustomDisplayString<\/strong>: The CustomDisplayString is the attribute that stored the updated value of the message.<\/li>\n<li><strong>PublishedDisplayString<\/strong>: The PublishedDisplayString attribute is the attribute where the recently updated custom display string value will populate once the display string entity is published.<\/li>\n<\/ul>\n<p>Both the attribute values above are null by default. After modifying and publishing, we get a value for them.<\/p>\n<p>Below is the screenshot where both of the attribute values are showing null by default.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-34363\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/1OOB-messages.jpeg\" alt=\"OOB messages\" width=\"1189\" height=\"780\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/1OOB-messages.jpeg 1189w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/1OOB-messages-300x197.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/1OOB-messages-1024x672.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/1OOB-messages-768x504.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/1OOB-messages-660x433.jpeg 660w\" sizes=\"(max-width: 1189px) 100vw, 1189px\" \/><\/p>\n<p>We can update the same with the help of a plugin or JavaScript. Now, we&#8217;ll go into detail about how to update the same using a JavaScript file.<\/p>\n<p>For demonstration purposes, in CRM I have changed the entity name \u2018Opportunity\u2019 to \u2018Connection\u2019.<\/p>\n<p><strong>Scenario<\/strong>: I tried to change the currency of the connection(Opportunity) record which is already associated with the quote or product, but got a \u201cCannot update opportunity currency\u201d error message. It seems the message is not populating with the updated entity name. So I want to update the same message to \u201cCannot update connection currency\u201d. To accomplish this I have written the below code.<\/p>\n<p>Below is the code that I have registered on the <strong>Onload<\/strong> event of the connection(Opportunity) entity which will update the value of a specific display string.<\/p>\n<pre class=\"lang:css gutter:true start:1\">getmessage = async (executionContext: any) =&gt; {\r\n\r\nlet functionName: string = \"getmessage\";\r\n\r\ntry {\r\n\r\n\/\/create a object\r\n\r\nvar displayStringValue = {\r\n\r\ncustomdisplaystring: \"Cannot update connection currency\",\r\n\r\ndisplaystringid: \"48ad073b-a4aa-ed11-9884-000d3a0a7684\",\r\n\r\n};\r\n\r\n\/\/call API for update a record\r\n\r\n\/\/@ts-ignore\r\n\r\nXrm.WebApi.updateRecord(\"displaystring\", displayStringValue.displaystringid, displayStringValue).then(\r\n\r\nfunction success(result) {\r\n\r\nconsole.log(\"Update display string successfully\");\r\n\r\nthis.publishCustomization();\r\n\r\n},\r\n\r\nfunction (error) {\r\n\r\nconsole.log(error.message);\r\n\r\n}\r\n\r\n);\r\n\r\n}\r\n\r\ncatch (e) {\r\n\r\n\/\/show alert\r\n\r\nXrm.Navigation.openAlertDialog({ title: \"error\", text: e.message });\r\n\r\n}\r\n\r\n}\r\n\r\n}<\/pre>\n<p>In the above code, first, I\u2019ve defined the display string record that I want to update. Then, we set the CustomDisplayString property to the value that we want and set the displaystringid to the ID of the display string we want to update.<\/p>\n<p>After setting the object for the display string, we will use the Xrm.WebApi.updateRecord method to send the update request to the Microsoft Dynamics 365 Web API. The first parameter of this method is the entity name, which is DisplayString. The second parameter is the ID of the record to update, which is the displaystringid property of the display string record.<\/p>\n<p>Now, for verifying, I went to the Microsoft Dynamics 365 CRM and check whether the message is updated or not, So that time I noticed that only the custom display string was updated, and published Display string value remains null.<\/p>\n<p>In the below screenshot, where we got only the custom display string value.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-34361\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/3OOB-messages.jpeg\" alt=\"OOB messages\" width=\"1506\" height=\"748\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/3OOB-messages.jpeg 1506w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/3OOB-messages-300x149.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/3OOB-messages-1024x509.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/3OOB-messages-768x381.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/3OOB-messages-660x328.jpeg 660w\" sizes=\"(max-width: 1506px) 100vw, 1506px\" \/><\/p>\n<p>Due to that in CRM, the error message also Shows the old message value.<\/p>\n<p>Below is the screenshot of the old error message.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-34360\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages.jpeg\" alt=\"OOB messages\" width=\"1185\" height=\"774\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages.jpeg 1185w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages-300x196.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages-1024x669.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages-768x502.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages-660x431.jpeg 660w\" sizes=\"(max-width: 1185px) 100vw, 1185px\" \/><\/p>\n<p>For avoiding that we need to publish the customization for showing the updated string. We can publish the display string table directly from Power Apps or use the below code.<\/p>\n<p>Below is the code to perform publish customizations programmatically.<\/p>\n<pre class=\"lang:css gutter:true start:1\">publishCustomization = \u00a0() =&gt; {\r\n\r\nlet functionName: string = \"publishCustomization\";\r\n\r\ntry {\r\n\r\n\u00a0\r\n\r\n\/\/@ts-ignore\r\n\r\nXrm.WebApi.execute(\r\n\r\n\"PublishAllXml\",\r\n\r\nnull\r\n\r\n).then(\r\n\r\nfunction success(result) {\r\n\r\nconsole.log(\"Customizations published..\");\r\n\r\n},\r\n\r\nfunction (error) {\r\n\r\nconsole.log(error.message);\r\n\r\n}\r\n\r\n);\r\n\r\n}\r\n\r\ncatch (e) {\r\n\r\n\/\/show alert\r\n\r\nXrm.Navigation.openAlertDialog({ title: \"error\", text: e.message });\r\n\r\n}\r\n\r\n\u00a0\r\n\r\n}<\/pre>\n<p>To verify if customizations are published successfully, we are printing the record to the console.<\/p>\n<p><img decoding=\"async\" class=\"alignnone size-full wp-image-34360\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages.jpeg\" alt=\"OOB messages\" width=\"1185\" height=\"774\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages.jpeg 1185w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages-300x196.jpeg 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages-1024x669.jpeg 1024w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages-768x502.jpeg 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/03\/4OOB-messages-660x431.jpeg 660w\" sizes=\"(max-width: 1185px) 100vw, 1185px\" \/><\/p>\n<p><strong>Conclusion<\/strong><\/p>\n<p>In this way, we can easily update display string messages for an entity. This can help you build more customizable and user-friendly messages.<\/p>\n<p><a href=\"https:\/\/www.inogic.com\/product\/productivity-apps\/business-process-dynamics-365-crm-to-do-checklist-sequence\" target=\"_blank\" rel=\"noopener\"><img decoding=\"async\" class=\"alignnone  wp-image-34377\" src=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/04\/Business-Process-Checklist-2.png\" alt=\"\" width=\"828\" height=\"207\" srcset=\"https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/04\/Business-Process-Checklist-2.png 800w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/04\/Business-Process-Checklist-2-300x75.png 300w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/04\/Business-Process-Checklist-2-768x192.png 768w, https:\/\/www.inogic.com\/blog\/wp-content\/uploads\/2023\/04\/Business-Process-Checklist-2-660x165.png 660w\" sizes=\"(max-width: 828px) 100vw, 828px\" \/><\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Introduction: In Microsoft Dynamics 365 CRM, the display string messages are those messages which are shown on the Forms, error Popups, etc. which provide appropriate information to the users. However, a user can modify a message as per the business case. To accomplish this, Microsoft now provides us with a feature where we can directly\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.inogic.com\/blog\/2023\/04\/programmatically-update-oob-messages-in-microsoft-dynamics-365-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":[18,2361],"tags":[2685],"class_list":["post-34359","post","type-post","status-publish","format-standard","hentry","category-dynamics-365-v9-2","category-technical","tag-oob-messages"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/34359","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=34359"}],"version-history":[{"count":0,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/posts\/34359\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/media?parent=34359"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/categories?post=34359"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.inogic.com\/blog\/wp-json\/wp\/v2\/tags?post=34359"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}