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 } ); } } ); } );
yes sir try it ones
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 ☺️
Step 1) Edit the member's profile from the admin dashboard (you can click the edit link from the member's menu to edit a profile).
Step 2) Click the “Notify User” checkbox.
Step 3) Fill in the email subject and body field with the message you want to send to the member.
Step 4)When you save the user’s profile, it will send the email to this member.
Raj
@GOS have you been able to check this?
@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.
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
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/link-search-results-in-table-to-product-page-based-on-row-solved
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???
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
let CurrentUserId = wixUsers.currentUser.id $w('#dataset1').setFieldValue("userId", CurrentUserId) $w('#dataset1').save()
BackendCode
Create a Backend web module file SendEmail.jsw
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.
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" }) }
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
Examples
Send a Triggered Email to a site member
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
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.
Anyone available?
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.
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
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
Sends a Triggered Email to the currently logged-in site member.
https://www.wix.com/corvid/reference/wix-users-backend.html#emailUser
Sends a Triggered Email to the specified site member.