Variables in User Invite Template

I’m sending user invites from my front end (with the code below), and would like to pass a couple variables to the User Invite Template - email address and app name. Is this possible?

var emailBody = {
    "first_name":"Jo",
    "last_name":"Satriani",
    "email":"satriani@gmail.com",
    "confirmed":false,
    "is_active":true,
    "is_sys_admin":false,
    "role_id":1
};
$.ajax({
    beforeSend: function(request) {
        request.setRequestHeader("X-DREAMFACTORY-SESSION-TOKEN", sessionStorage.SESSION_TOKEN);
        request.setRequestHeader("X-DREAMFACTORY-APPLICATION-Name", "admin");
    },
    type: 'POST',
    url: 'http://myServer.cloudapp.net/rest/system/user?send_invite=true',
    data: JSON.stringify(emailBody),
    cache: false
});

The fields in the just-created user object can be referenced in the email template. See the default user invite template in the Config–>Email templates section of the admin console.

Hi {first_name},...

Yes, this works for first_name in the user invite, but when I include {email} in the same template it just prints “{email}” in the resulting email, even though I’m sending an email field and value in the object.

I still haven’t found a solution. To be clear, I’m not just using a normal email template - I want to send variables when I create a new user, which triggers the assigned invite template to be sent.

I looked a bit at /opt/bitnami/apps/dreamfactory/htdocs/vendor/dreamfactory/lib-php-common-platform/src/Resources/User/Register.php and tried a couple things to get the email address to be available in the invite template in the same way first_name, confirm_code, etc. are, but no luck so far.

Can anyone direct me on what to edit in order to allow printing the email address of the created user in the invite template?

Thanks!

See line 201 in vendor/dreamfactory/lib-php-common-platform/src/Resources/System/User.php

$_userFields = array( 'first_name', 'last_name', 'display_name', 'confirm_code' );

It only makes these fields available. You can add email to the list.

I have created a bug report to make this more flexible in the future.

3 Likes

Perfect, thanks Todd! I’ll work with the same file to see about adding additional custom variables, but the email address was the most important one.

You can also use the {to} variable, as I found out the hard way.

Thanks hassen_isa. That’ll save me from having to update those php files each time I upgrade DF.

It would be really nice if I could find all kind of system variables the system supports in mail templates, I can’t find any mention of the {to} variable in the dreamfactory documentation for example.

The {to} variable is not mentioned here: https://wiki.dreamfactory.com/DreamFactory/Features/Lookups