Please suggest a script. Our requirement is following.
1) Inactive user name will get from access request ticket customfield.
2) Check the user if it is Inactive, make the user to active.
3) If user not found update ticket with comment
We are looking to use the script in Escalation Services or inside workflow transaction of access ticket.
Hello,
Assuming your custom field type is text field, the code should be something like this:
import com.atlassian.jira.bc.user.ApplicationUserBuilder
import com.atlassian.jira.bc.user.UserService
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.user.ApplicationUser
CustomField customField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("custom field name")
String userName = issue.getCustomFieldValue(customField)
ApplicationUser user = ComponentAccessor.getUserManager().getUserByName(userName)
if(user){
if(!user.isActive()){
UserService userService = ComponentAccessor.getComponent(UserService.class)
ApplicationUserBuilder userBuilder = userService.newUserBuilder(user)
user = userBuilder
.active(true)
.build()
UserService.UpdateUserValidationResult updateUserValidationResult = userService.validateUpdateUser(user)
if(updateUserValidationResult.isValid()){
userService.updateUser(updateUserValidationResult)
}else{
log.error("User update is invalid. Error: ${updateUserValidationResult.getErrorCollection()}")
}
}
}else{
ApplicationUser currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
String commentBody = "comment text"
ComponentAccessor.getCommentManager().create(issue, currentUser, commentBody, false)
}
Hi @Ivan Tovbin,
Thank Ivan! that's a nice code. One more pint I missed to add. Once user activated, ticket need to move close status else ticket need to move 'In Progress' status.
Also the customfield is number field.
Regards,
Sukanta
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hmm, what data is stored in your custom field if its a number field? I though you have a user name there or something. Could you please clarify?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ivan Tovbin,
This is user name only. We are using employee ID as user name. Also if user is inactive than only script will activate them. Otherwise if user have no jira account or user is already activated then secript will put a comment and move the ticket to In Progress.
Thanks
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.