Script-changes to userprofile are not visible in profile history

Any issue about Cyclos 4 scripting and Webservices

Moderators: hugo, alexandre, rmvanarkel

Post Reply
sandrab
Posts: 13
Joined: Tue Sep 11, 2018 8:26 am

Script-changes to userprofile are not visible in profile history

Post by sandrab »

Hi,

When a groovy script changes the contents of a userprofile field of a Cyclos user, this is not visible in the profile history of the user. Is it possible to configure this somehow?

Thanks,
Sandra

Using Cyclos 4.9.1

luis
Posts: 190
Joined: Fri Feb 17, 2006 11:01 am

Re: Script-changes to userprofile are not visible in profile history

Post by luis »

For this you have to use the regular save of the UserService, through DTOs, not directly manipulating the entity.
Example:

Code: Select all

def dto = userService.load(userId)
def fields = scriptHelper.wrap(dto)
fields.fieldName = value
userService.save(dto)
Luis Fernando Planella Gonzalez
Cyclos development team

sandrab
Posts: 13
Joined: Tue Sep 11, 2018 8:26 am

Re: Script-changes to userprofile are not visible in profile history

Post by sandrab »

Works indeed, this is nice to know. Thanks Luis!

sandrab
Posts: 13
Joined: Tue Sep 11, 2018 8:26 am

Re: Script-changes to userprofile are not visible in profile history

Post by sandrab »

While this works great when the code is in an extension script on validating or creating a user, or when using the 'Run as' script functionality, we would like to use this in a custom web service script as well. We need this script to run as Guest. Does that mean we can not use userService.load() in this case?

When I try, the userService.load() results in an exception:

org.cyclos.impl.access.ScriptSessionData cannot be cast to org.cyclos.impl.access.GuestSessionData

The code used:

Code: Select all

String userName = 'user_x'	// Adjust this to an existing username.
try{
	def user = conversionHandler.convert(User, userName)
	def usrDTO = userService.load(user.id)
	def usr = scriptHelper.wrap(usrDTO)
	usr.email = "tester@mysite.com"
	userService.save(usrDTO)
	return "Saved in user ${userName}."
} catch(Exception e){
	return "\nException: ${e.getMessage()}"
}

rmvanarkel
Posts: 244
Joined: Tue Oct 05, 2010 1:14 pm

Re: Script-changes to userprofile are not visible in profile history

Post by rmvanarkel »

Dear Sandra,

Sorry for the inconvenience, at this moment it is not possible to run this script as guest, we will make sure this works in Cyclos 4.11.

Thanks for your patience!

sandrab
Posts: 13
Joined: Tue Sep 11, 2018 8:26 am

Re: Script-changes to userprofile are not visible in profile history

Post by sandrab »

I can confirm it works, now we are using Cyclos 4.11.1.

Thanks!
Sandra

Post Reply