Get user custom information with Groovy Script

Hello everyone.

I have created 2 custom user fields to enter your document and start date . This data will be used to automate a part of the process.

I have not been able to obtain the data, the closest I was to achieving it was using this code:

List customUserInfoList = apiAccessor.getIdentityAPI().getCustomUserInfo(processInitiator.id, 0, 100);

for (var in customUserInfoList) {
  logger.info("Custom Data: " + var.properties.toString())
}

LOG:

03-Feb-2022 14:59:54.429 INFORMATION [Bonita-Worker-1-01] org.slf4j.Logger$info.call Custom Data: [value:43138036, userId:101, class:class org.bonitasoft.engine. identity.CustomUserInfo, definition:CustomUserInfoDefinitionImpl [id=1, name=Document, description=]]
03-Feb-2022 14:59:54.429 INFORMATION [Bonita-Worker-1-01] org.slf4j.Logger$info.call Custom Data: [value:31-12-2020, userId:101, class:class org. prettysoft.engine.identity.CustomUserInfo, definition:CustomUserInfoDefinitionImpl [id=2, name=Start Date, description=]]


With that log I see that I get the data, but they are inside an object.

Can someone help me to get the value of "Document"?

Here is the solution!!

 

import org.bonitasoft.engine.identity.CustomUserInfo
import org.bonitasoft.engine.identity.UserNotFoundException

def logger = org.slf4j.LoggerFactory.getLogger('Obtener documento')
def document

try {
    def processInitiator = apiAccessor.getIdentityAPI().getUser(apiAccessor.getProcessAPI()
        .getProcessInstance(processInstanceId)
        .getStartedBy())

    List < CustomUserInfo > customUserInfoList = apiAccessor.getIdentityAPI().getCustomUserInfo(processInitiator.id, 0, 100);

    for (CustomUserInfo customUserInfo: customUserInfoList) {

        if (customUserInfo.getDefinition().getName().equalsIgnoreCase("document")) {
            logger.info("# document: " + customUserInfo.getValue() + " #");
            document = customUserInfo.getValue();
        }
    }

} catch (UserNotFoundException e) {
    // Handle UserNotFoundException here
    // Was the process started by the system (e.g.: a start event) ?
    // Has the user who started the process instance been deleted ?
}

return document

Good to see you’ve found your answer!