Hello everyone,
I am creating a script that allows a certain user to register jobs on behalf of another user (Scrennshot_1), this script seems to work correctly but when defining the user, this is not displayed in the same way as when the user is the That logs the job in the request detail (Screenshot_2), what am I doing wrong to get users to show up like that?
The script I am running is as follows:
import com.atlassian.jira.issue.worklog.WorklogImpl
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
import com.atlassian.jira.security.JiraAuthenticationContext
def componentManager = ComponentManager.getInstance()
def componentAccesor = ComponentAccessor.getIssueManager()
def workLogManager = ComponentAccessor.getWorklogManager()
def issueManager = ComponentAccessor.getIssueManager()
//def issue = componentAccesor.getIssueObject("TELEFIN-1")
def logsForIssue = workLogManager.getByIssue(issue)
def size = 0
if(logsForIssue == null || logsForIssue.size() > 0){
size = logsForIssue.size()-1
}
def workloggs = workLogManager.getById(logsForIssue[size].id)
CustomField cfUsuario = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Usuario")
JiraAuthenticationContext jiraAuthenticationContext = ComponentManager.getComponentInstanceOfType(JiraAuthenticationContext.class)
ApplicationUser user = jiraAuthenticationContext.getLoggedInUser()
def usuario = issue.getCustomFieldValue(cfUsuario)?(ApplicationUser)issue.getCustomFieldValue(cfUsuario):user
workLogManager.delete(user, workloggs, null, false)
def wli = new WorklogImpl(null, issue, 0, usuario.name, null, workloggs.startDate, null, null, workloggs.getTimeSpent())
workLogManager.create(user, wli, null, false)
issue.setCustomFieldValue(cfUsuario, null)
issueManager.updateIssue(user, issue, EventDispatchOption.DO_NOT_DISPATCH, false);


Regards.