Is there a way to set a default Template on the Print/Merge Document screen? I have a common workflow which uses a customised search, which then goes to the Print/Merge Document action (or a clone thereof) and I would like this to default to the correct template.

I have tried using Javascript to change the Select box, but it seems to have timing problems and sometimes the Template just does not appear.

With thanks, Tony

2 Answers 2


I finally got a JavaScript delay to work with the following code. It's pretty ad hoc (to use a polite term) but does seem to work. Cycles until it can see that the ckEditor header has loaded, then waits another half second for luck and selects the required template.

Regards, Tony

function checkBold (rep) {
    // console.log('Bold: ' + $('#cke_24').is(':visible') );
    // Waits for the Bold button in the CKEditor to appear
    if ($('#cke_24').is(':visible') ) {
            $('.crm-contact-task-pdf-form-block select#template').val('71').change();
        }, 500);                
    if (rep > 0) {setTimeout(() => checkBold(rep-1), 100);}
checkBold(100);                 // Limit of 10 seconds

The timing issue is probably ckeditor hasn't finished loading yet so it can't fill in the message body. Is your javascript wrapped in .ready()?

Otherwise you could try using the buildForm() hook in an extension and look up the template html for that template and then call setDefaults()

$result = civicrm_api3('MessageTemplate', 'get', array(
  'id' => 66, // or whatever the id is

    'subject' => $results['values']['msg_subject'],
    'html_message' => $results['values']['msg_html'],
  • Thank you. My JS is wrapped in .ready() and I have tried adding various other delays, with mixed success. I will definitely look at using the build(Form() hook though.
    – user6274
    Jan 4, 2020 at 13:01

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.