# Trigger email from dashboard to member

**URL:** <https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [June 17, 2020, 2:40pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565 "2020-06-17T14:40:54Z")\
**Posts on this page:** 18\
**Page:** 1

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 17, 2020, 2:40pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/1 "2020-06-17T14:40:54Z")

</div>

Hello! I have a real estate website and I created a dashboard from where I verify member houses before they become public. I want to send an email from there to the publication’s owner/member when I click the button for ‘‘approve publication’’ so they know their house form has been accepted and published. How can I modify this triggered-email-code so it sends to the email of the person who submitted the form I verify, and not the logged in user since I do this from my dashboard? Thank you for your help.

import wixUsers **from** ‘wix-users’ ;

$w.onReady( **function** () {  
$w( “#dataset1” ).onAfterSave( () =\> {  
**if** (wixUsers.currentUser.loggedIn) {  
**const** userId = wixUsers.currentUser.id;

```
  wixUsers.emailUser( 'S1dpbcZ' , userId, { 
      variables: { 
        nombredelsuscriptor: $w( '#input1' ).value, 
        nombreinmueble: $w( '#input2' ).value 
      } 
    } ) 
    .then( () => { 

```

// do something after the email was sent successfully  
} )  
. **catch** ( (err) =\> {  
// handle error that prevented the email from being sent  
} );  
}  
} );  
} );

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 17, 2020, 3:01pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/2 "2020-06-17T15:01:31Z")

</div>

If you want to send an email to a specific member, then use Wix Users backend API, otherwise you can only send an email to the user who is currently logged in.

[https://www.wix.com/corvid/reference/wix-users.html#emailUser](https://www.wix.com/corvid/reference/wix-users.html#emailUser)  
Sends a Triggered Email to the currently logged-in site member.

[https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser](https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser)  
Sends a Triggered Email to the specified site member.

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 17, 2020, 5:07pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/3 "2020-06-17T17:07:36Z")

</div>

Thank you @GOS, does the second option allows me to get automatically the member email of the house I am verifying eventhough I am doing it from my admin manager dashboard? how would the code be if mixed with the above triggered email code?

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 18, 2020, 12:01am UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/4 "2020-06-18T00:01:36Z")

</div>

The dashboard pages let you do the same as normal pages.  
[https://support.wix.com/en/article/corvid-working-with-dashboard-pages#:~:text=To%20make%20your%20page%20available,to%20elements%20on%20your%20page.](https://support.wix.com/en/article/corvid-working-with-dashboard-pages#:~:text=To%20make%20your%20page%20available,to%20elements%20on%20your%20page.)

How are you receiving the members info for the house listing?

If that is through a user input form to yourselves, then you can make sure that the form saved into the dataset gets saved with the users Id and then you can just take the user Id from the dataset field and use it for the user Id for the triggered email.

Or use the members email from the form and make a query to your users data, whether that be the Wix Members app Members/PrivateMembersData, or your own collection, for a matching email and get the user id form the results and use it send the email.  
[https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields#emails-emails-1](https://support.wix.com/en/article/corvid-wix-members-privatemembersdata-collection-fields#emails-emails-1)

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 18, 2020, 2:17pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/5 "2020-06-18T14:17:54Z")

</div>

Thank you for your reply GOS! Yes I gather my info through an input form. My doubt regarding the dashboard was because the triggered email code I have is coded for logged in users, so if i trigger it from my dashboard nothing will happen and so thats why I need the same code but modified to get the email of the user who filled out the form. I understand and agree with everything you have explained. My issue is I dont know how to do the code since I am a beginner. I want to **take the user Id of the current form I am verifying from the dataset field and use it for the user Id for the triggered email** , or **take the email from the current input form I am verifying directly** as you said. So far I have this\>\>\> Which modifications should I do to make it work according to that need?

**import** wixUsers **from** ‘wix-users’ ;

$w.onReady( **function** () {  
$w( “#dataset1” ).onAfterSave( () =\> {  
**if** (wixUsers.currentUser.loggedIn) {  
**const** userId = wixUsers.currentUser.id;

```
  wixUsers.emailUser( 'S1dpbcZ' , userId, { 
      variables: { 
        nombredelsuscriptor: $w( '#input1' ).value, 
        nombreinmueble: $w( '#input2' ).value 
      } 
    } ) 
    .then( () => { 

```

// do something after the email was sent successfully  
} )  
. **catch** ( (err) =\> {  
// handle error that prevented the email from being sent  
} );  
}  
} );  
} );

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 19, 2020, 3:15pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/6 "2020-06-19T15:15:12Z")

</div>

Anyone available?

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 19, 2020, 8:10pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/7 "2020-06-19T20:10:35Z")

</div>

Don’t use the Wix Users API and the emailUser() function as that will only apply to the currently logged in user, hence why the code uses onAfterSave so that it sends the triggered email to the currently logged in user who submitted the form.

You need to be using the Wix Users Backend API and the emailUser() function from that instead.  
[https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser](https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser)

**Examples**  
Send a Triggered Email to a site member

```javascript
import wixUsersBackend from 'wix-users-backend';

export function myBackendFunction() {
  let userId = // get user ID

  wixUsersBackend.emailUser("emailID", userId)
    .then( () => {
      // email has been sent
    } )
    .catch( (err) => {
      // there was an error sending the email
  } );
}

```

Send a Triggered Email to a site member with variable values

```javascript
import wixUsersBackend from 'wix-users-backend';

export function myBackendFunction() {
  let userId = // get user ID
  let value1 = // value for variable1

  wixUsersBackend.emailUser("emailID", userId, {
      "variables": {
        "variable1": value1,
        "variable2": "value for variable2"
      }
    } )
    .then( () => {
      // email has been sent
    } )
    .catch( (err) => {
      // there was an error sending the email
    } );
}

```

Also, don’t forget that each dataset will have the id field hidden by default, so if you use the Members app collection or your own members dataset, then you can simply just get the id from there and copy and paste it into a user input on your page, which your code can use to get the userId from.

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 19, 2020, 10:06pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/8 "2020-06-19T22:06:50Z")

</div>

😞 I know that code but I dont know how to use it. Which part goes backend and which one goes front end? How do I get the user id of the form I am currently correcting from the dashboard?

**import** wixUsersBackend **from** ‘wix-users-backend’ ;

export function myBackendFunction() {  
**let** userId = **what should I write here to get the ID. Copy paste the especific user id doesent work for me. I need it to be found automaticaly depending on the form I am verifying**

wixUsersBackend.emailUser( “S1dpbcZ” , userId, {  
“variables” : {  
“nombredelsuscriptor” : $w( ‘#input1’ ).value,  
“nombreinmueble” : $w( ‘#input2’ ).value  
}  
} )  
.then( () =\> {  
// email has been sent  
} )  
. **catch** ( (err) =\> {  
// there was an error sending the email  
} );  
}

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 19, 2020, 11:22pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/9 "2020-06-19T23:22:21Z")

</div>

Okay I see now, I will get back to asap with that. :+1:

---

<div class="post-metadata">

**Author:** ![vijayad1540](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/vijayad1540/32/17971_2.png) [@vijayad1540](https://forum.wixstudio.com/u/vijayad1540)\
**Post date:** [June 20, 2020, 2:43am UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/10 "2020-06-20T02:43:21Z")

</div>

Save the userId in page code while saving the publication into dataset

## Page Code

This code should be on the user page while creating house publication for approval

```javascript
let CurrentUserId = wixUsers.currentUser.id
$w('#dataset1').setFieldValue("userId", CurrentUserId)
$w('#dataset1').save()

```

* * *

## BackendCode

Create a Backend web module file SendEmail.jsw

```javascript
import wixUsersBackend from'wix-users-backend';

exportfunction myBackendFunction(userId, Value1, Value2) {
wixUsersBackend.emailUser("S1dpbcZ", userId, {
"variables": {
"nombredelsuscriptor": Value1,
"nombreinmueble": Value2}    
} )    
.then( () => {// email has been sent } )
.catch( (err) => {// there was an error sending the email } );}

```

* * *

## Dashboard Page Code

On Dashboard retrieve it from database  
I think you use the repeater to display the Publication items for approval. So I am using $item.

```javascript
import { myBackendFunction } from 'backend/SendEmail';

$item("#Button").onClick( (event) => {
let $item = $w.at(event.context);
let UserID = $item('#dataset2').getCurrentItem().userId
let Value1 = $item("#input1").value;
let Value2 = $item("#input2").value;
return myBackendFunction(userId, Value1, Value2)
.then( () => { $item("#text1").text = "Email has been sent successfully" })
}

```

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 22, 2020, 10:39pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/11 "2020-06-22T22:39:15Z")

</div>

Thank you @Vijay. I have done everything so far, however I am not using a repeater. I see all properties to be approved in a table, then I select the one I want to verify and it opens all the input fields with the info of that propertie. When I am done modifying it I just click a button that says ‘approve’ and done. So the dashboard code is not working for me, how should it be instead? I guess just an onclick event for that button? and replace the $item with $w???

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 22, 2020, 11:33pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/12 "2020-06-22T23:33:37Z")

</div>

Okay, I am back quickly again. I see that you are using a table here, so that is even better.

As your input is coming from members only, any data that they submit through your form will be linked to them with their userId in a hidden field in the dataset that you are using to save the inputs into.

Therefore, you can simply setup your results table to show this hidden id field and then use onRowSelect to get the rows data and use that to populate your own user inputs on the page.

So you can have a user input on your page that is populated with the userId of that member and you can use that for the userId for the emailUser function itself for when you click on the submit button.  
[https://www.wix.com/corvid/reference/$w.Table.html#onRowSelect](https://www.wix.com/corvid/reference/$w.Table.html#onRowSelect)

These two old posts should get you moving on a little bit.  
[https://www.wix.com/corvid/forum/community-discussion/open-local-page-on-table-row-select](https://www.wix.com/corvid/forum/community-discussion/open-local-page-on-table-row-select)  
[https://www.wix.com/corvid/forum/community-discussion/link-search-results-in-table-to-product-page-based-on-row-solved](https://www.wix.com/corvid/forum/community-discussion/link-search-results-in-table-to-product-page-based-on-row-solved)

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 22, 2020, 11:34pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/13 "2020-06-22T23:34:27Z")

</div>

I will see if i can make time to get back on here very soon to see if you are still struggling or if you have sorted it.

---

<div class="post-metadata">

**Author:** ![givemeawhisky](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/givemeawhisky/32/5383_2.png) [@givemeawhisky](https://forum.wixstudio.com/u/givemeawhisky)\
**Post date:** [June 23, 2020, 12:31am UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/14 "2020-06-23T00:31:05Z")

</div>

Okay, to add further here, if you go back to your original form, then you can simply get a users Id and add it in a read only box with this simple code.

You can use this to simply get the users Id in the first place if you find that you can’t manage to use the hidden by default id field already and then again use setFieldValue() function to save it to the correct field in your form submission dataset.

Then you can use that in your table and get the userId for the emailUser function from that.

```javascript
import wixUsers from 'wix-users';

$w.onReady(function () {
let user = wixUsers.currentUser.id; 
$w('#input1').value = user; 
}); 

```

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 23, 2020, 1:42am UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/15 "2020-06-23T01:42:16Z")

</div>

@GOS Awesome, thank you for your continuous guidance and patience, I will work on this tomorrow and let you know how it goes! I am learning and adapting to this code universe so it might take me a bit to put it together. I’ll be back to you asap​:dizzy:💫💫

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 23, 2020, 10:53pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/16 "2020-06-23T22:53:14Z")

</div>

@GOS so this is my update. I have done everything you described so far. I have a table, when I click a row a user input form is opened all populated by the info of the selected table row. I added a text field and connected it to the ID field from the dataset, however this shows the property ID, not the \_owner ID. Is that right?

**I added this code in my dashboard page (which is where I am completing the approval process):**

**import** wixUsersBackend **from** ‘wix-users-backend’ ;

export function myBackendFunction() {  
**let** userId = $w( ‘#text289’ ).text,  
**let** value1 = $w( ‘#input1’ ).value, (here I get Error: keyword ’ let’ is reserved)  
**let** value2 = $w( ‘#input2’ ).value

wixUsersBackend.emailUser( “S1dpbcZ” , userId, {  
“variables” : {  
“variable1” : value1,  
“variable2” : valie2,  
}  
} )  
.then( () =\> {  
// email has been sent  
} )  
. **catch** ( (err) =\> {  
// there was an error sending the email  
} );  
}

**Then in my backend code I added a module called SendEmail.jsw with the code:**

**import** wixUsersBackend **from** ‘wix-users-backend’ ;

export function myBackendFunction(userId, Value1, Value2) {  
wixUsersBackend.emailUser( “S1dpbcZ” , userId, {  
“variables” : {  
“nombredelsuscriptor” : Value1,  
“nombreinmueble” : Value2 }  
} )  
.then( () =\> { ‘email sent’ } )  
. **catch** ( (err) =\> { ‘there was an error sending the email’ } );}

Is this correct? Because of the ‘let’ error I mentioned above, the page is not working properly so I havent been able to check if the email code is working.

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 29, 2020, 8:45pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/17 "2020-06-29T20:45:38Z")

</div>

@GOS have you been able to check this?

---

<div class="post-metadata">

**Author:** ![adelaidacastrov](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/adelaidacastrov/32/19612_2.png) [@adelaidacastrov](https://forum.wixstudio.com/u/adelaidacastrov)\
**Post date:** [June 30, 2020, 1:57pm UTC](https://forum.wixstudio.com/t/trigger-email-from-dashboard-to-member/18565/19 "2020-06-30T13:57:28Z")

</div>

Thank you Raj! I didnt know you could do that, I will keep it in mind! However what I am trying to do is send the email automatically when I verify their properties with the verify button from a dashboard I designed for this purpose. This way I do all at once ☺
