How to Update Email Address and Screen Name with Groovy Scripts

If you, as an admin user, wish to modify the screen name or email address of site members, you will need to input the password. It is possible that the admin user may not be aware of the password.

 

 

Groovy is a scripting language with Java-like syntax for the Java platform. check this page how to run the groovy scripts in Liferay

 

Groovy is a scripting language that resembles Java in terms of syntax and is designed for use with the Java platform. You can find instructions on how to execute Groovy scripts in Liferay on this page.

 

 

Using Groovy scripts, admin users can update the screen name. Here is a simple script that uses the updateScreenName method of UserLocalServiceUtil**** needs to be replaced with the long userID and replace #### with Screen Name

By utilizing Groovy scripts, administrator users have the ability to update the screen name. Below is a straightforward script that employs the UserLocalServiceUtil's updateScreenName method. Replace **** with the lengthy userID and #### with the desired screen name.

import com.liferay.portal.kernel.service.UserLocalServiceUtil;

import com.liferay.portal.kernel.model.User;

 

try

{

UserLocalServiceUtil.updateScreenName(****,"####");

}

catch(Exception e)

{

out.println("ERROR is"+e.getMessage());

}

 

Using Groovy scripts, admin users can update the Email address. Here is a simple script that uses the updateEmailAddress method of UserLocalServiceUtil**** needs to be replaced with the long userID .

Through the use of Groovy scripts, administrator users can also update the email address. Take a look at this simple script that utilizes the UserLocalServiceUtil's updateEmailAddress method. Replace **** with the lengthy userID.

 

import com.liferay.portal.kernel.service.UserLocalServiceUtil;

import com.liferay.portal.kernel.model.User;

 

try

{

 

User existingUser = UserLocalServiceUtil.getUser(****);

UserLocalServiceUtil.updateEmailAddress(existingUser.getUserId(),existingUser.getPassword(),"test@testmail.com","test@testmail.com");

 

}

catch(Exception e)

{

out.println("ERROR is"+e.getMessage());

}

 

More Blog Entries