JSM Cloud - JSM Server / User creation sync

Hello

We have a connection with Exalate between a JSM Cloud and a JSM Server.
When a user creates a ticket in the JSM Cloud we want to pass as a reporter or as a participant to the ticket created in JSM Sever. We have a code to create the user in the connection configuration in the server, in the incoming sync section:

------------------------------/////////
def localUserForRemoteReporter = userHelper.getByEmail(replica.reporter.email)
if (localUserForRemoteReporter == null) {
// create the user if s/he doesn’t exist
localUserForRemoteReporter = userHelper.createUser(replica.reporter.username,
“changeme”,
replica.reporter.email,
replica.reporter.displayName)
}
issue.reporter = localUserForRemoteReporter
issue.customFields.“Participantes de la solicitud”.value += localUserForRemoteReporter
------------------------------/////////

I performed some tests and was able to see that performing the following changes to the script fixes the issue:

------------------------------/////////
def localUserForRemoteReporter = userHelper.getByEmail(replica.reporter.email)
if (localUserForRemoteReporter == null) {
// create the user if s/he doesn’t exist
localUserForRemoteReporter = userHelper.createUser(replica.reporter.displayName,
“changeme”,
replica.reporter.email,
replica.reporter.displayName)
}
issue.reporter = localUserForRemoteReporter
issue.customFields.“Participantes de la solicitud”.value += localUserForRemoteReporter
------------------------------/////////

The user then was created but has been created as a jira user (with license), not as a portal customer.

Is it possible for him to be created as a portal user, or as a participant, or as a user but without being added to the default groups that give access to the product?

Participants are not being copied to the jira server unless they previously exist as users in jira server.

Thanks in advance

Creating this on behalf of esther.ortega@xeridia.com

Hi,

I believe you should be able to do this, but not with the native createUser() method, but rather by direct interaction with the Jira API. I tried the following (hardcoded values) and it did the trick for me. Hopefully it gives you some ideas:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.project.ProjectManager
import com.atlassian.jira.security.roles.ProjectRoleManager

def username = "customer_email@example.com"
def password = "RandomPassword123!" // Or generate something random
def emailAddress = "customer_email@example.com"
def fullName = "Customer Name"
def projectKey = "SON" // <-- your Service Management project key

def userUtil = ComponentAccessor.userUtil
def userManager = ComponentAccessor.userManager
def groupManager = ComponentAccessor.groupManager
def projectManager = ComponentAccessor.projectManager
def projectRoleManager = ComponentAccessor.getComponent(ProjectRoleManager)

def project = projectManager.getProjectByCurrentKey(projectKey)

// Check if user already exists
def existingUser = userManager.getUserByName(username)
def newUser

if (existingUser) {
    log.info "User already exists: ${existingUser.name}"
    newUser = existingUser
} else {
    newUser = userUtil.createUserNoNotification(username, password, emailAddress, fullName)
    log.info "User created: ${newUser.name}"
    
    // Add to 'jira-servicedesk-customers' group
    def customerGroup = groupManager.getGroup("jira-servicedesk-customers")
    if (customerGroup) {
        userUtil.addUserToGroup(customerGroup, newUser)
    }
}

Thanks
Majid