Developer forum

Forum » CMS - Standard features » Get User on OMC

Get User on OMC

Mario Santos
Reply

Hi there,

 

I need to update the current user that is receiving an email using OMC. I've set an email with "Render content for each recipient" checked.

On the template I've tried to use User.GetCurrentUser() but got the following results:

  • When the email is sent the User.GetCurrentUser() is null;
  • When using the preview functionality the User.GetCurrentUser() retrieves the backoffice logged user;

How can I get the UserID or UserEmail that is receiving the email? Any thoughts?

 

Thanks in advance,

BR, Mário


Replies

 
Nicolai Pedersen
Reply

Hi Mario

User.GetCurrentUser() will of course give the logged in user.

To get access to the user currently being sent to, you can get it from PageView.Current.Context.GetValue("User") which will retun the user instance for you. Of course this will only work for mails that sends out information based on a user. If it is an abondoned cart or some other recipient provider, you cannot be sure it holds a user.

 
Mario Santos
Reply

Hi Nicolai,

 

Thank you for your fast reply. 

The GetValue("User") is always return null:

Pageview.Context.GetValue("User");
Dynamicweb.Frontend.PageView.Current().Context.GetValue("User");

 

What am I doing wrong?

 

BR, Mário

 
Nicolai Pedersen
Reply

I have no clue.

Add a debugger and see what happens! What recipient provider are you using?

 
Mario Santos
Reply

I can't debug because I'm not working locally. I'm using the Dynamicweb users provider.

 
Nicolai Pedersen
Reply

Of course you can debug locally, and you should. https://msdn.microsoft.com/en-us/library/dn986851.aspx

 
Mario Santos
Reply

Hi Nicolai,

 

I said I'm not working/running locally. The solution is installed on a server (which I only access throught FTP).

BTW, thanks for the link.

 

BR, Mário

 
Ricardo Pereira
Ricardo Pereira
Reply

Hi Nicolai,

I'm having the same issue than Mario.
​The User.GetCurrentUser() doesn't returns the logged user, it returns the user logged on the Backoffice.
We don't have a local solution so, we cannot do the debug.
It happens on Dynamicweb version: 8.8.1.6 

Can you please take a look?

Best regards,

Ricardo Pereira

 
Nicolai Pedersen
Reply

@Ricardo - the answer to you is the same then. GetCurrentUser() returns the user who is executing the backend, if any user is logged in. Because it happens in the context of the backend when you send out emails. No recipients are logged in when sending emails.

And I will be happy to find someone to help you out, but it will be a payable service and they would need a local copy of your solution.

You are welcome to install a solution locally so you can debug. Dynamicweb.Frontend.PageView.Current().Context contains the information that is available, and it depends on your setup so you have to look for yourself.

 
Ricardo Pereira
Ricardo Pereira
Reply

Thank you Nicolai.

The solution is:
User user = Pageview.Context.GetValue("User") as User;

 
Nicolai Pedersen
Reply

Wow, exactly what i wrote...

 

You must be logged in to post in the forum