Hi Folks,
I have been trying to populate the current username for the user picker field upon checking the checkbox as Approved, when uncheck Approved clear username.
RCT Late Approval [] Approved (Checkbox)
RCT Late Approver (Single user picker)
tried below code did not work
//Populate username//
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
@BaseScript FieldBehaviours fieldBehaviours
def rctLate = getFieldByName("RCT Late Approval")
def rctLateApproval = rctLate.getValue() as String
if (rctLateApproval == "Approved")
{
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def funcCompleteApprover = getFieldById("customfield_13606") //customfield_13606 RCT Late Approver
funcCompleteApprover.setFormValue(currentUser.username)
}
Need help.
Regards
T
Hi @Teja
What error do you have ?
Can you try this
funcCompleteApprover.setFormValue(currentUser.getUserame()
)
instead of
funcCompleteApprover.setFormValue(currentUser.username)
https://docs.atlassian.com/software/jira/docs/api/7.0.6/com/atlassian/jira/user/ApplicationUser.html
I don't see any logs error using above script.
When I change `username` to `getUsername()`
I see error like this
Infact, If I use only script without checkbox if condtion the user population works fine
import groovy.transform.BaseScript
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.atlassian.jira.component.ComponentAccessor
@BaseScript FieldBehaviours fieldBehaviours
def rctLate = getFieldByName("RCT Late Approval")
def rctLateApproval = rctLate.getValue() as String
//if (rctLateApproval == "Approved"){
def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def funcCompleteApprover = getFieldById("customfield_13606")
funcCompleteApprover.setFormValue(currentUser.username)
Note: Script that I using in the Initialiser
Regards
Teja
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Tweak in the if condition works now
import groovy.transform.BaseScript import com.onresolve.jira.groovy.user.FieldBehaviours import com.atlassian.jira.component.ComponentAccessor @BaseScript FieldBehaviours fieldBehaviours def rctLate = getFieldByName("RCT Late Approval") def rctLateApproval = rctLate.getValue() as String def funcCompleteApprover = getFieldById("customfield_13606") if (rctLateApproval?.contains ("Approved")){ def currentUser = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser() //customfield_13606 RCT Late Approver funcCompleteApprover.setFormValue(currentUser.username) }else{ funcCompleteApprover.setFormValue("") }
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.