Error when trying to save a User Record

Any issue about Cyclos 4 scripting and Webservices

Moderators: alexandre, hugo, rmvanarkel

Post Reply
EdwinMor
Posts: 22
Joined: Tue Sep 15, 2020 10:31 am
Location: El Salvador
Contact:

Error when trying to save a User Record

Post by EdwinMor »

Hi

I was working on a script that saves a User Record, which produces the following error from a user perspective:
'There was an error while accessing the database'

When looking at the logs it shows this:
Caused by: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: RecordCustomFieldPossibleValue#null. Order: 0.

I have pinpointed out that the field type that is causing the error is a single selection field (when I comment the line that adds the field to the Record objet the error dissapears). The relevant portion of the script is the following:

Code: Select all

def currencyPossibleValue = new RecordCustomFieldPossibleValue()
currencyPossibleValue.internalName = currencyInternalName
currencyPossibleValue.field = new RecordCustomField()
currencyPossibleValue.field.internalName = scriptParameters.recordInternalName

def recordType = entityManagerHandler.find(UserRecordType, recordTypeName)
def newParams = new RecordDataParams([user: new UserLocatorVO(id: user.id),
                    recordType: new RecordTypeVO(id: recordType.id)])
def dto = recordService.getDataForNew(newParams).getDto()
wrapped[currencyField] = currencyPossibleValue
recordService.save(dto)
The weird thing about this error is that I am running the exact same script on another server and it is working completely fine.

#######################################################

Minor Bug report
-------------------------------------------------------
Cyclos version: 4.15.13
Project: Web_new
User: Member
Menu: Banking > Operations
Installation(s): Installation on own server
-------------------------------------------------------
Description:
When trying to save a new User Record that has a Single Selection field I get the following error: There was an error while accessing the database
-------------------------------------------------------
URL: https://osher.360vew.com/
Username: edwinadmin
Password: Time#75500
-------------------------------------------------------
Error log: Caused by: java.lang.IllegalStateException: During synchronization a new object was found through a relationship that was not marked cascade PERSIST: RecordCustomFieldPossibleValue#null. Order: 0.

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

Re: Error when trying to save a User Record

Post by luis »

You can't instantiate entities and set their internal names to reference them.
But you can (and should) do this with VO's or other models.
Try the following:

Code: Select all

def newParams = new RecordDataParams([user: new UserLocatorVO(id: user.id),
    recordType: new RecordTypeVO(internalName: recordTypeName)])
def dto = recordService.getDataForNew(newParams).dto
// Watch out, you were missing this line in your example 
def wrapped = scriptHelper.wrap(dto)
wrapped[currencyField] = currencyInternalName
recordService.save(dto)
Luis Fernando Planella Gonzalez
Cyclos development team
EdwinMor
Posts: 22
Joined: Tue Sep 15, 2020 10:31 am
Location: El Salvador
Contact:

Re: Error when trying to save a User Record

Post by EdwinMor »

You are right, I was missing that line when I was copying the relevant parts of the script.

Thank you, this works wonderfuly.

Regards
Post Reply