<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://sugarclub.sugarai.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/dev-club/f/questions-answers/6420/how-to-call-docmerge-from-a-hook</link><description>Hi guys, 
 
 does one of you already try to call DocMerge from a Hook (or similar code context) ? 
 Of course I know it can be done through BPM ; but what we want to do can be trigger and handle using BPM. 
 Also, I would like to see if error handling</description><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/30506?ContentTypeID=1</link><pubDate>Mon, 18 Dec 2023 14:25:02 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:84fb748e-b4ab-4fa3-8fba-69c364d0b411</guid><dc:creator>Rafael Fernandes</dc:creator><description>&lt;p&gt;&lt;a href="/members/jkuehlthau"&gt;Justin Kuehlthau&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;You can set a prefix and a suffix in the UI (see image below), but it will be static,&amp;nbsp;meaning you cannot set something-{name}-contract.docx.&lt;/p&gt;
&lt;p&gt;rafa&lt;/p&gt;
&lt;p&gt;&lt;img style="max-height:375px;max-width:500px;" alt=" " src="/resized-image/__size/1000x750/__key/communityserver-discussions-components-files/54/4370.image.png" /&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/30498?ContentTypeID=1</link><pubDate>Fri, 15 Dec 2023 02:34:10 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:c137558b-2cfc-4ede-a39b-ceecf0094f5e</guid><dc:creator>Justin Kuehlthau</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/rafael-fernandes"&gt;Rafael Fernandes&lt;/a&gt;&amp;nbsp;,&lt;/p&gt;
&lt;p&gt;Do you know if it is possible to set the name of the file that is generated?&amp;nbsp; Right now, it concatenates the Name of the record and the name of the Document Template.&amp;nbsp; I&amp;#39;d like to be able to set a custom filename result.&lt;/p&gt;
&lt;p&gt;Thank you,&lt;br /&gt;Justin Kuehlthau&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/29114?ContentTypeID=1</link><pubDate>Tue, 30 May 2023 19:45:17 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:0678e612-8bf7-40be-b66c-9ea534b48b3d</guid><dc:creator>Rafael Fernandes</dc:creator><description>&lt;p&gt;Hi&amp;nbsp;&lt;a href="/members/frinaldi"&gt;Frédéric Rinaldi&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Here&amp;#39;s the feedback I got from engineering:&lt;/p&gt;
&lt;p&gt;Example code should be inside the bpm &lt;code&gt;modules/pmse_Inbox/engine/PMSEElements/PMSEDocumentMerge.php&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="php"&gt;public function merge($data, \SugarBean $bean, $flowData): void
    {
        $convert = $data-&amp;gt;act_convert_to_pdf ?? false;
        $templateId = $data-&amp;gt;act_document_template-&amp;gt;value;
        $templateName = $data-&amp;gt;act_document_template-&amp;gt;text;
        $recordId = $bean-&amp;gt;id;
        $recordModule = $bean-&amp;gt;module_dir;

        $mergeType = $this-&amp;gt;getMergeType($convert, $templateId);
        if ($mergeType) {
            $docMerge = new DocumentMergeApi();
            $api = new \RestService();
            $docMerge-&amp;gt;merge($api, [
                &amp;#39;mergeType&amp;#39; =&amp;gt; $mergeType,
                &amp;#39;templateId&amp;#39; =&amp;gt; $templateId,
                &amp;#39;templateName&amp;#39; =&amp;gt; $templateName,
                &amp;#39;useRevision&amp;#39; =&amp;gt; true,
                &amp;#39;recordId&amp;#39; =&amp;gt; $recordId,
                &amp;#39;recordModule&amp;#39; =&amp;gt; $recordModule,
                &amp;#39;flowData&amp;#39; =&amp;gt; json_encode($flowData),
            ]);
        } else {
            throw new PMSEElementException(&amp;quot;Document Merge: No merge type&amp;quot;, $mergeType, $this);
        }
    }&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;div class="c-virtual_list__item c-virtual_list__item--initial-activeitem" id="C027ND0R6E4-1683137059.936819-thread-list-Thread_1685461965.084189"&gt;
&lt;div class="c-message_kit__background c-message_kit__background--hovered c-message_kit__message c-message_kit__thread_message"&gt;
&lt;div class="c-message_kit__hover c-message_kit__hover--hovered"&gt;
&lt;div class="c-message_kit__actions c-message_kit__actions--default"&gt;
&lt;div class="c-message_kit__gutter"&gt;
&lt;div class="c-message_kit__gutter__right"&gt;
&lt;div class="c-message_kit__blocks c-message_kit__blocks--rich_text"&gt;
&lt;div class="c-message__message_blocks c-message__message_blocks--rich_text"&gt;
&lt;div class="p-block_kit_renderer"&gt;
&lt;div class="p-block_kit_renderer__block_wrapper p-block_kit_renderer__block_wrapper--first"&gt;
&lt;div class="p-rich_text_block" dir="auto"&gt;
&lt;div class="p-rich_text_section"&gt;&lt;code&gt;$flowData&lt;/code&gt; shouldn&amp;#39;t matter but for safety, I would put something like &amp;#39;{}&amp;#39;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="c-virtual_list__item" id="C027ND0R6E4-1683137059.936819-thread-list-Thread_1685462178.832789"&gt;
&lt;div class="c-message_kit__background c-message_kit__message c-message_kit__thread_message"&gt;
&lt;div class="c-message_kit__hover"&gt;
&lt;div class="c-message_kit__actions c-message_kit__actions--default"&gt;
&lt;div class="c-message_kit__gutter"&gt;
&lt;div class="c-message_kit__gutter__left"&gt;&lt;/div&gt;
&lt;div class="c-message_kit__gutter__left"&gt;You are sending all the params that are needed. You could debug it by adding the &amp;#39;flowData&amp;#39; param and if it still doesn&amp;#39;t work you could check the network settings.&amp;nbsp;&lt;br /&gt;&lt;br /&gt;&lt;/div&gt;
&lt;div class="c-message_kit__gutter__left"&gt;Thanks,&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/29099?ContentTypeID=1</link><pubDate>Fri, 26 May 2023 07:15:34 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:91603ea8-ad74-47b7-b824-22e728eb40e5</guid><dc:creator>Groupe Sugar</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/rafael-fernandes"&gt;Rafael Fernandes&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I tried with the following code:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="php"&gt;&amp;lt;?php

    $api = new DocumentMergeApi();
    $args = [
        &amp;#39;mergeType&amp;#39; =&amp;gt; &amp;#39;convert&amp;#39;,
        &amp;#39;useRevision&amp;#39; =&amp;gt; 1,
        &amp;#39;templateName&amp;#39; =&amp;gt; &amp;#39;test&amp;#39;,
        &amp;#39;templateId&amp;#39; =&amp;gt; &amp;#39;9a7a7546-e5c8-11ed-af10-0242ac11002e&amp;#39;,
        &amp;#39;recordId&amp;#39; =&amp;gt; &amp;#39;497703a6-efd9-11ed-88c2-0242ac11002a&amp;#39;,
        &amp;#39;recordModule&amp;#39; =&amp;gt; &amp;#39;Accounts&amp;#39;,
    ];
    $service = new RestService();
    $merge_req_id = $api-&amp;gt;merge($service, $args);&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;I can see the document_merge record in the DocMerge popup as well as in the document_merges db table.&lt;/p&gt;
&lt;p&gt;But it ends up with an error in the sugarcrm.log:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;Exception in Controller: SugarException: Server error: `POST https://document-merge-eu-west-2-prod.service.sugarcrm.com/merge` resulted in a `504 Gateway Time-out` response:
 (truncated...)
 in /var/www/html/modules/DocumentMerges/clients/base/api/DocumentMergeApi.php:141&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;I launched the same document generation using the interface and it went well. I don&amp;#39;t see any difference in the 2 document generations (looking at the db records and at the parameters send to the api).&lt;/p&gt;
&lt;p&gt;Any idea about what is going wrong?&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Thank you,&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Sylvain&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/28906?ContentTypeID=1</link><pubDate>Fri, 05 May 2023 06:58:27 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:c918f0d3-4081-4af4-a05a-09d32e363c4a</guid><dc:creator>Fr&amp;#233;d&amp;#233;ric Rinaldi</dc:creator><description>&lt;p&gt;Thanks &lt;a href="/members/rafael-fernandes"&gt;Rafael Fernandes&lt;/a&gt; ; I will try.&lt;/p&gt;
&lt;div id="ext-mouse-move"&gt;&lt;/div&gt;
&lt;div id="ext-mouse-down"&gt;&lt;/div&gt;
&lt;div id="ext-mouse-up"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/28900?ContentTypeID=1</link><pubDate>Thu, 04 May 2023 18:19:11 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:24e31b58-4e4c-4cbc-b76f-02e54e0030f8</guid><dc:creator>Rafael Fernandes</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/frinaldi"&gt;Frédéric Rinaldi&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Here is some ideas we came up with:&lt;/p&gt;
&lt;p&gt;You can create the hook and call the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="c-mrkdwn__code"&gt;merge&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function from the DocumentMergeApi. Just instantiate the class and call the function. The function should receive the proper arguments. They can be identified from the code inside the function&lt;/p&gt;
&lt;div class="c-virtual_list__item c-virtual_list__item--initial-activeitem" id="C027ND0R6E4-1683137059.936819-thread-list-Thread_1683215496.937289"&gt;
&lt;div class="c-message_kit__background c-message_kit__background--hovered c-message_kit__background--labels c-message_kit__background--labels--later c-message_kit__message c-message_kit__thread_message"&gt;
&lt;div class="c-message_kit__hover c-message_kit__hover--hovered"&gt;
&lt;div class="c-message_kit__actions c-message_kit__actions--default"&gt;
&lt;div class="c-message_kit__labels c-message_kit__labels--light"&gt;
&lt;div class="c-message_kit__gutter"&gt;
&lt;div class="c-message_kit__gutter__right"&gt;
&lt;div class="c-message_kit__blocks c-message_kit__blocks--rich_text"&gt;
&lt;div class="c-message__message_blocks c-message__message_blocks--rich_text"&gt;
&lt;div class="p-block_kit_renderer"&gt;
&lt;div class="p-block_kit_renderer__block_wrapper p-block_kit_renderer__block_wrapper--first"&gt;
&lt;div class="p-rich_text_block" dir="auto"&gt;
&lt;pre class="c-mrkdwn__pre"&gt;   $data = [
            'mergeType' =&amp;gt; $request-&amp;gt;getValidInputPost('mergeType'),
            'useRevision' =&amp;gt; $request-&amp;gt;getValidInputPost('useRevision') ?? true,
            'templateName' =&amp;gt; $request-&amp;gt;getValidInputPost('templateName'),
            'templateId' =&amp;gt; $request-&amp;gt;getValidInputPost('templateId', 'Assert\Guid'),
            'recordId' =&amp;gt; $request-&amp;gt;getValidInputPost('recordId', 'Assert\Guid'),
            'recordModule' =&amp;gt; $request-&amp;gt;getValidInputPost('recordModule'),
            'parentId' =&amp;gt; $request-&amp;gt;getValidInputPost('parentId'),
            'parentModule' =&amp;gt; $request-&amp;gt;getValidInputPost('parentModule'),
            'maxRelate' =&amp;gt; $request-&amp;gt;getValidInputPost('maxRelate') ?? static::MAX_RETRIEVE,
        ];&lt;/pre&gt;
&lt;div class="p-rich_text_section"&gt;Also&amp;nbsp;you&amp;#39;d need to create for each merge, a&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="c-mrkdwn__code"&gt;DocumentMerge&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;record. This actually tracks the merge status. Once&amp;nbsp;you call the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="c-mrkdwn__code"&gt;merge&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;function they will immediately get a response from the server. The response is the merge request id. After that, the server will update the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="c-mrkdwn__code"&gt;DocumentMerge&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;record that was created earlier, with the status messages, like&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="c-mrkdwn__code"&gt;Retrieving data&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;,&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;code class="c-mrkdwn__code"&gt;Document Generated&lt;/code&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;or error messages.&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="c-message_actions__container c-message__actions"&gt;
&lt;div class="c-message_actions__group"&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div class="c-virtual_list__item" id="C027ND0R6E4-1683137059.936819-thread-list-Thread_input"&gt;
&lt;div class="p-threads_footer__input_container p-threads_footer__input_container--sticky_composer"&gt;
&lt;div class="p-threads_footer__input p-message_input_unstyled p-message_input_unstyled--dark"&gt;
&lt;div class="p-message_input__input_container_unstyled c-wysiwyg_container c-wysiwyg_container--theme_dark c-wysiwyg_container--with_footer c-wysiwyg_container--theme_dark_bordered c-wysiwyg_container--double_decker c-basic_container c-basic_container--size_medium"&gt;
&lt;div class="c-basic_container__body"&gt;
&lt;div class="c-wysiwyg_container__formatting"&gt;
&lt;div class="p-texty_sticky_formatting_bar"&gt;
&lt;div&gt;
&lt;div class="p-composer__body p-composer__body--visible p-composer__body--unstyled"&gt;Hope this helps,&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/28887?ContentTypeID=1</link><pubDate>Thu, 04 May 2023 06:35:21 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:a8272782-830b-43f7-9231-6551df07f203</guid><dc:creator>Fr&amp;#233;d&amp;#233;ric Rinaldi</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/rafael-fernandes"&gt;Rafael Fernandes&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;Thanks for your feedback.&lt;/p&gt;
&lt;p&gt;Here is our use case&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;we need to generate a mail for several customers&lt;/li&gt;
&lt;li&gt;using DocMerge, I can generate a single document merging all record for printing --&amp;gt; that is OK&lt;/li&gt;
&lt;li&gt;I also need to generate a single document for each customer, in ordre to archive the document in the EDM solution&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;we were thinking about doing this using BPM but we face several issues without any way to be sure that the document was correctly generated.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;So we would like to trigger a hook and create several individual job action to perform the docmerge.&lt;/p&gt;
&lt;p&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Fred&lt;/p&gt;
&lt;div id="ext-mouse-move"&gt;&lt;/div&gt;
&lt;div id="ext-mouse-down"&gt;&lt;/div&gt;
&lt;div id="ext-mouse-up"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/28884?ContentTypeID=1</link><pubDate>Wed, 03 May 2023 18:08:11 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:e9a276cc-12e4-4853-993c-4f4537d6fc03</guid><dc:creator>Rafael Fernandes</dc:creator><description>&lt;p&gt;Hi &lt;a href="/members/frinaldi"&gt;Frédéric Rinaldi&lt;/a&gt;,&lt;/p&gt;
&lt;p&gt;I had a quick chat with engineering and they believe you can achieve what you need through DocMergeApi, as for error handling, most (if not all) are coming directly from the DocMerge service.&lt;/p&gt;
&lt;p&gt;Perhaps if you share a little more about your use case, I can get a better answer from the team.&lt;/p&gt;
&lt;p&gt;rafa&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: How to call DocMerge from a Hook ?</title><link>https://sugarclub.sugarai.com/thread/28880?ContentTypeID=1</link><pubDate>Wed, 03 May 2023 15:46:59 GMT</pubDate><guid isPermaLink="false">5c521d64-519d-47a6-9065-134618b211bf:3594efeb-5e2d-4ba4-97dd-4bbff2a4b86e</guid><dc:creator>Fr&amp;#233;d&amp;#233;ric Rinaldi</dc:creator><description>&lt;p&gt;nobody did that ??&lt;/p&gt;
&lt;div id="ext-mouse-move"&gt;&lt;/div&gt;
&lt;div id="ext-mouse-down"&gt;&lt;/div&gt;
&lt;div id="ext-mouse-up"&gt;&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>