News.mscrm-addons.com BlogHello and welcome to our blog! What can we do for you? Are you looking for further technical information or step-by-step instructions to our products? Or would you like to read the latest news on mscrm-addons? Please feel free to browse our blog for detailed information and to share our posts! https://www.mscrm-addons.com/BlogCustom ExportToWord Buttons in DocumentsCorePack for Dynamics 365https://www.mscrm-addons.com/Blog/PostId/10081/custom-exporttoword-buttons-in-documentscorepack-for-dynamics-365DocumentsCorePack (DCP),DCP 365Thu, 29 Mar 2018 10:16:58 GMT<p style="margin-bottom: 0.0001pt; text-align: justify;">This article describes how you can create custom Dynamics 365 menu buttons with custom JavaScript functions to execute the DocumentsCorePack ExportToWord (aka &ldquo;PrintInWord&rdquo;) process. This article is only relevant if you use the DocumentsCorePack client (Template Designer) to generate documents.</p> <p style="margin-bottom: 0.0001pt; text-align: justify;">&nbsp;</p> <p style="margin-bottom: 0.0001pt; text-align: justify;">This blog article<span style="text-align: justify;">&nbsp;</span>applies&nbsp;<span style="text-align: justify;">only</span> to Dynamics 365 <span style="text-align: justify;">-&nbsp;</span>version 8.2 and higher.&nbsp;</p> <p style="margin-bottom: 0.0001pt; text-align: justify;">&nbsp;</p> <p style="margin-bottom: 0.0001pt; text-align: justify;">Basic JavaScript knowledge is required.</p> <p style="margin-bottom: 0.0001pt; text-align: justify;">&nbsp;</p> <p style="margin-bottom: 0.0001pt;"><span style="color: #0077b3;"><strong>When can this be helpful?</strong></span></p> <p style="margin-bottom: 0.0001pt;">For example, you want to define a specific template which should be used for the process.</p> <p style="margin-bottom: 0.0001pt;">Or you want to do any pre-operations like checking the status of the target record (e.g. invoice has to be paid).</p> <p style="margin-bottom: 0.0001pt;">&nbsp;</p> <p style="margin-bottom: 0.0001pt;"><span style="color: #0077b3;"><strong>Configure custom buttons</strong></span></p> <p style="margin-bottom: 0.0001pt;">First, start the <strong>Configuration - DocumentsCorePack for Dynamics 365</strong>, connect to your organization and launch the <strong>Client &amp; Server Based generation settings</strong>.</p> <p style="margin-bottom: 0.0001pt;">More information can be found in chapter &ldquo;Organization Overview&ldquo; of the <a href="http://www.mscrm-addons.com/Portals/0/MSCRM2015/DCP/DocumentsCorePack_Server_and_Client_Based_Install._Guide_v.2015.9_Oct_2015.pdf">Install Guide</a>.&nbsp;</p> <p style="margin-bottom: 0.0001pt;">&nbsp;</p> <p style="margin-bottom: 0.0001pt;">In the so opened window, hit on the <strong>[Advanced Button Configuration]</strong>-button, like you can see in the following figure.</p> <div class=" data-plugin-options="> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"> <a title="The Advanced Button Configuration " href="/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure1_Advanced_Button_Config.png"> <img alt="The Advanced Button Configuration" width="504" height="282,5" class="img-responsive" src="/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure1_Advanced_Button_Config.png" /> </a></div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em>Figure 1: The Advanced Button Configuration</em></div> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em><br /> </em></p> <p style="margin-bottom: 0.0001pt;">Thereafter the <strong>Advanced Button Configuration-</strong>dialog will appear. In this dialog, you can select the entity that you want to manage.</p> <p style="margin-bottom: 0.0001pt;">E.g. Already existing custom<strong>&nbsp;<span>[Export To Word]</span></strong>-buttons will be listed and can be deleted.</p> <p style="margin-bottom: 0.0001pt;"> </p> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><a title="The Advanced Button Configuration-dialog " href="http://www.mscrm-addons.com/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure2_Advanced_Button_Config_dialog.png"><img alt="The Advanced Button Configuration-dialog" class="img-responsive" src="http://www.mscrm-addons.com/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure2_Advanced_Button_Config_dialog.png" width="229,5" height="241,5" /></a></div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">Figure 2: The Advanced Button Configuration-dialog</div> <p>&nbsp;</p> <p style="margin-bottom: 0.0001pt;">If you press the<strong> [Add]</strong>-button, the following <strong>Edit button</strong>-dialog opens.&nbsp;</p> </div> <p> </p> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><a title=" The Edit Button-dialog " href="http://www.mscrm-addons.com/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure3_Edit_Button.png"><img alt=" The Edit Button-dialog" class="img-responsive" src="http://www.mscrm-addons.com/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure3_Edit_Button.png" width="343,5" height="209,5" /></a></div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">Figure 3: The Edit Button-dialog</div> <p>&nbsp;</p> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><span style="color: #0077b3;">Button Name</span><br /> Gives you the possibility to define a custom name for your button.</p> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><span style="color: #0077b3;">JS Library</span><br /> Cannot be changed.&nbsp;</p> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><span style="color: #0077b3;">JS Functions</span><br /> Select the JavaScript function that should be executed if you hit the generated button.&nbsp;</p> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">The DocumentsCorePack Configuration Tool already includes predefined JavaScript template functions which can be used to get started (underneath you will find a description):&nbsp;</p> <ul> <li class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">ptmDCPCustomExportToWordAction</li> <li class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">ptmDCPCustomExportToWordActionAccountWithTemplate</li> <li class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">ptmDCPCustomExportToWordActionSingleRecordCheck</li> <li class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">CustomPrintInWordActionAccount (deprecated)</li> </ul> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">With a click on the<strong> [Modify JavaScript]</strong>-button the JavaScript web resource (ptm_dcp_custombuttonsactions.js) is opened in a new Dynamics 365 window.</p> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><a title="The JavaScript web resource " href="http://www.mscrm-addons.com/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure4_JS_Web_resource.png"><img alt="The JavaScript web resource" class="img-responsive" src="http://www.mscrm-addons.com/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure4_JS_Web_resource.png" width="470,5" height="280,5" /></a></div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">Figure 4: The JavaScript web resource</div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">&nbsp;</div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">&nbsp;&nbsp;</div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">Hit the <strong>[Text Editor]</strong>-button to edit its content.&nbsp;</div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><a title=" Edit Web Resource Content " href="http://www.mscrm-addons.com/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure5_edit_content.png"><img alt=" Edit Web Resource Content" class="img-responsive" src="http://www.mscrm-addons.com/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure5_edit_content.png" width="470,5" height="280,5" /></a></div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">Figure 5: Edit Web Resource Content</div> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">&nbsp;</p> <span style="color: #0077b3;"><strong>JavaScript functions&nbsp;</strong></span><br /> The methods described below are part of this web resource. The latest version of the script can be download <a href="http://www.mscrm-addons.com/Portals/0/Blog/Download/ptm_dcp_custombuttonactions.zip?ver=2018-03-28-112319-723">here</a>. <br /> <br /> <p style="margin-bottom: 0.0001pt;">The function <strong>ptmDCPCustomExportToWordAction</strong> (line 33 to 43) shows the simplest way to start the ExportToWord process. After executing, the DCP Client will show the template selection dialog. This example function is ready to use and works for different entities.</p> <p style="margin-bottom: 0.0001pt;">&nbsp;</p> <p style="margin-bottom: 0.0001pt;"><em><span style="color: black;">ptmDCPCBCustomButton.startExportToWord(selectedIds, typeCode, selectedItemCount, entityName);</span></em></p> <p style="margin-bottom: 0.0001pt;"><span style="font-size: inherit; font-style: inherit; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight: inherit; font-family: inherit;">This function starts the ExportToWord process, like you can see in the following figure.</span></p> <p style="margin-bottom: 0.0001pt;"><span style="font-size: inherit; font-style: inherit; font-variant-ligatures: inherit; font-variant-caps: inherit; font-weight: inherit; font-family: inherit;"> </span></p> <div class=" data-plugin-options="> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"> <a title="Start the ExportToWord process " href="/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure6_Example_Code.png"> <img alt="Start the ExportToWord process" height="280,5" class="img-responsive" src="/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure6_Example_Code.png" /> </a></div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em>Figure 6: Start the ExportToWord process </em></div> </div> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">&nbsp;&nbsp;</p> <p style="margin-bottom: 0.0001pt;">The function <strong>ptmDCPCustomExportToWordActionAccountWithTemplate </strong>(line 46 to 58) shows how the ExportToWord process can be started with a specific template. After executing, the DCP Client will use the defined template (Account_Overview.docx) instead of showing the template selection dialog.</p> <p style="margin-bottom: 0.0001pt;">This example function works for accounts only because its template is designed for accounts.</p> <p style="margin-bottom: 0.0001pt;">&nbsp;</p> <p style="margin-bottom: 0.0001pt;"><em><span style="color: green;">//doSomething();</span></em></p> <p style="margin-bottom: 0.0001pt;">Can be replaced with any custom code. E.g. check the status.</p> <p style="margin-bottom: 0.0001pt;">​</p> <p style="margin-bottom: 0.0001pt;"><em><span style="color: blue;">var</span></em><em><span style="color: black;"> nameOfDCPTemplate = </span></em><em><span style="color: #a31515;">"Account_Overview.docx"</span></em><em><span style="color: black;">;</span></em></p> <p style="margin-bottom: 0.0001pt;">Define the name of the DCP template. Any existing template of the entity account can be used.</p> <p style="margin-bottom: 0.0001pt;">&nbsp;</p> <p style="margin-bottom: 0.0001pt;"><em><span style="color: black;">ptmDCPCBCustomButton.startExportToWord(selectedIds, typeCode, selectedItemCount, entityName, nameOfDCPTemplate);</span></em></p> <p style="margin-bottom: 0.0001pt;">Starts the ExportToWord process and passes on the template.<br /> ​</p> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"> <a title="Start the ExportToWord process and pass on the template " href="/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure7_Example2.png"> <img alt="Start the ExportToWord process and pass on the template" height="280,5" class="img-responsive" src="/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure7_Example2.png" /> </a></div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em>Figure 7: Start the ExportToWord process and pass on the template </em></div> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}">&nbsp;&nbsp;</p> <p style="margin-bottom: 0.0001pt;">The function <strong>ptmDCPCustomExportToWordActionSingleRecordCheck </strong>(line 63 to 96) shows how the entity name and the ID of the reference-record can be accessed (first for a process started from GRID/SubGRID, second from a FORM).</p> <p style="margin-bottom: 0.0001pt;">​</p> <p style="margin-bottom: 0.0001pt;">Finally, it starts the ExportToWord process.</p> <p style="margin-bottom: 0.0001pt;">​</p> <div class=" data-plugin-options="> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"> <a title="The function ptmDCPCustomExportToWordActionSingleRecordCheck" href="/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure8_Example3.png"> <img alt="The function ptmDCPCustomExportToWordActionSingleRecordCheck" height="280,5" class="img-responsive" src="/Portals/0/Blog/Custom_ExportToWord_Buttons_DCP/Figure8_Example3.png" /> </a></div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em>Figure 8: The function ptmDCPCustomExportToWordActionSingleRecordCheck</em></div> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em>&nbsp;&nbsp;</em></p> <p style="margin-bottom: 0.0001pt;">You can add custom functions to the web resource as well. Ensure that you use the same input parameters as the sample functions have.</p> <p style="margin-bottom: 0.0001pt;">Therewith your custom functions can be selected in the DocumentsCorePack dialog they have to be placed above&nbsp;on the line <span style="color: green;">///////// DCPHELPERFUNCTIONS /////////</span></p> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em> </em></p> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em><span style="font-size: 13px;"><span style="background-color: #fcfcfc; text-align: justify;"><strong>That&rsquo;s it!</strong>&nbsp;We appreciate your feedback! Please share your thoughts by sending an email to&nbsp;<a href="mailto:support@mscrm-addons.com">support@mscrm-addons.com</a></span><span style="background-color: #fcfcfc; text-align: justify;">.</span></span></em></p> <p class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"><em> </em></p> </div> <div class="lightbox" data-plugin-options="{'delegate': 'a', 'type': 'image', 'gallery': {'enabled': false}}"> <p style="margin-bottom: 0.0001pt;">&nbsp;</p> </div>10081