How to call DocMerge from a Hook ?

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 is better with code generation.

Best regards,

Fred

Parents
  • Hi ,

    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.

    Perhaps if you share a little more about your use case, I can get a better answer from the team.

    rafa

    SugarCRM | Principal Developer Advocate

  • Hi ,

    Thanks for your feedback.

    Here is our use case

    • we need to generate a mail for several customers
    • using DocMerge, I can generate a single document merging all record for printing --> that is OK
    • I also need to generate a single document for each customer, in ordre to archive the document in the EDM solution

    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.

    So we would like to trigger a hook and create several individual job action to perform the docmerge.

    Best regards,

    Fred

  • Hi ,

    Here is some ideas we came up with:

    You can create the hook and call the merge 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

       $data = [
                'mergeType' => $request->getValidInputPost('mergeType'),
                'useRevision' => $request->getValidInputPost('useRevision') ?? true,
                'templateName' => $request->getValidInputPost('templateName'),
                'templateId' => $request->getValidInputPost('templateId', 'Assert\Guid'),
                'recordId' => $request->getValidInputPost('recordId', 'Assert\Guid'),
                'recordModule' => $request->getValidInputPost('recordModule'),
                'parentId' => $request->getValidInputPost('parentId'),
                'parentModule' => $request->getValidInputPost('parentModule'),
                'maxRelate' => $request->getValidInputPost('maxRelate') ?? static::MAX_RETRIEVE,
            ];
    Also you'd need to create for each merge, a DocumentMerge record. This actually tracks the merge status. Once you call the merge function they will immediately get a response from the server. The response is the merge request id. After that, the server will update the DocumentMerge record that was created earlier, with the status messages, like Retrieving data , Document Generated or error messages.

    SugarCRM | Principal Developer Advocate

Reply Children
No Data