1

(This post is following a previous question I asked and is related to ErikH's answer: https://civicrm.stackexchange.com/a/31142/6991)

Context: I want to send per email an attached amended certificate (document ID #73). I tried the API explorer v3 and for one test user (id #54) it worked fine. Why an attached .pdf? Because it's an insurance certificate and it's important for each one of the 4000 members to have it personalized, that they can't modify it because of a legal issue and that they can print it easily. Once the membership is manually approved (it will always stay this way, again for legal issues), I want the team of volunteers to have the simple option to send it.

I have 2 questions that are related to each other. I read the documentation but as far as I am not so familiar to code, I don't know exactly what to do.

Question #1: is it possible to include some code in an existing template with general purpose within Civicrm? and which code? (and of course how?...)

PHP?

    $result = civicrm_api3('Pdf', 'create', [
  'contact_id' => 54,
  'template_id' => 73,
]);

or JavaScript

    CRM.api3('Pdf', 'create', {
  "contact_id": 54,
  "template_id": 73
}).then(function(result) {
  // do something with result
}, function(error) {
  // oops
});

Question #2: for this action, the API needs a contact ID and it's obvious it makes no sense to set it this way. Is there awy to use some fuzion fields instead like the civitoken {user.id}? I tried this way and the API explorer returns an error message. Is it possible or not? Thanks for any help.

2

Do I gather correctly you want to do this in many cases? The easiest option would then be to use the CiviRules extension to send the PDF so you do not have to code.

You could then set up something like if a membership of a certain type is added, send the PDF. That would make more sense to me then trying to add it to a template? I do not think that route will take you anywhere.

You can find more information about the CiviRules extension here: https://docs.civicrm.org/civirules/en/latest/

If CiviRules can not help you you would probably have to write an extension but you need to explain more about what is required exactly at what time for me to be able to help you with that.

  • yes I want to do this in many case. I will have a look at CiviRules. This thing is that I want this document to be generated automatically but manually sent as a file (not as the body of an email) when the team in charge of memberships validates the sign-up. And this is not related to time. I set the journey of a constituent but the only variables are join in date / start date / end date. I've created "to be confirmed" status that lasts 1 month after effective start date of membership (i.e when the payment is done, mainly online) in order to let the team have enough time to check the document. – Guillaume Sorel Jun 25 at 12:13
  • CiviRules did the job! This is exactly what I was looking for. Thanks so much Erik! – Guillaume Sorel Jun 25 at 12:45
  • Good to hear @Guillaume! – ErikH - CiviCooP Jun 25 at 17:52
2

Based on Erik's help, this is how I've dealt with my need:

  • When a new membership is manually checked and validated (for some legal issue), the team in charge of this task adds the member to a previously created dynamic group (sub group to membership called "validated membership")

  • using CiviRules, the new "validated" member automatically receives an email with a personnalized body AND a .pdf as attachment generated from a template.

this is the civirule:

  • Linked Condition(s): Contact (not) in Group(s) In one of selected groups ("validated membership")
  • Linked Action(s): Send PDF to e-mail address (printer or mailbox) "" with template "XXX" , template for e-mail body "YYY"
  • No Delay

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.