Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to enable/disable checkbox based on user in custom user picker field using behavior script?

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 27, 2018

Hi,

I have checkbox named 'Control Release' checkbox and I want to make this field enable for user who is in 'Control Release Owner' field on certain workflow statuses.

How to do that? 

Any help would be appreciated..

 

 

2 answers

1 accepted

1 vote
Answer accepted
Tansu Akdeniz
Community Champion
June 28, 2018

Hi @Teja,

  • Add new behavior.
  • Select a guide workflow.
  • Add Field (Control Release).
  • Add Except Condition
    •     Current user in user custom field value (Control Release Owner)
  • Add When Condition
    • Add workflow step / transition
  • Click Read-Only attribute.

So, the users, except the control release owner, will see the control release cf as read-only.

Tansu Akdeniz

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2018

@Tansu Akdeniz

So the "Control Release" [checkbox], will always available to "Control Release Owner".

May be I was not clear, I will explain with the example.

When the issue in 'Created' , 'Requested' status "Control Release" [checkbox] should always be disabled include "Control Release Owner" and when the issue in 'Control Release' status, then "Control Release" [checkbox] enabled for "Control Release Owner" only.

Tansu Akdeniz
Community Champion
June 28, 2018

Hi @Teja

You can add a groovy code in behaviours section like this;

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.user.ApplicationUser;

def issueId = getFieldById("id")
def controlReleaseCheckbox = getFieldById(getFieldChanged());      

def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def customFieldManager = ComponentAccessor.getCustomFieldManager();

Issue issue = ComponentAccessor.getIssueManager().getIssueObject(issueId.getValue() as Long);
String currentUserName = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser().getName();

CustomField controlReleaseUserCF = customFieldManager.getCustomFieldObject("customfield_10136");
def controlReleaseUser = issue.getCustomFieldValue(controlReleaseUserCF);

if(issue.getStatusId().equals("12345")){ //Control Release Status
    if(currentUserName.equals(controlReleaseUser.getName())){
        controlReleaseCheckbox.setReadOnly(false)
    } else{
        controlReleaseCheckbox.setReadOnly(true)
    }
} else{
   controlReleaseCheckbox.setReadOnly(true)
}

Tansu

Like • Emre Y. Okur likes this
Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 28, 2018

Hi @Tansu Akdeniz,

Thanks for you script.

I tried this in fields server-side script but I am getting error and not working as expected.

I shared screen shot.

And why are we using particular issueid instead of issue? 

Script.PNG

Tansu Akdeniz
Community Champion
June 28, 2018

Hi @Teja,

You must leave this line as below;

def issueId = getFieldById("id")

When you load a transition/edit pop-up, script gets the id of an issue with "id" parameter. Do not change it :) It should work.

Example; https://scriptrunner.adaptavist.com/4.3.5/jira/recipes/behaviours/subtask-default-fields.html

Tansu Akdeniz

Like • Emre Y. Okur likes this
Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2018 edited

Hi @Tansu Akdeniz,

Its working fine..

Thanks for your answer.

You're awesome..(•‿•)

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2018

Hi @Tansu Akdeniz,

Its working fine..

Thanks for your answer.

You're awesome..(•‿•)

Teja
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
June 29, 2018

Hi @Tansu Akdeniz,

Its working fine..

Thanks for your answer.

You're awesome..(•‿•)

0 votes
Tansu Akdeniz
Community Champion
June 29, 2018 edited

Glad to hear that. You are welcome =) @Teja

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, jira product discovery, jpd premium, product management, idea management, product discovery, jira premium, product planning, atlassian community, product development, roadmap planning, product prioritization, feature management

Introducing Jira Product Discovery Premium ✨

Jira Product Discovery Premium is now available! Get more visibility, control, and support to build products at scale.

Learn more
AUG Leaders

Atlassian Community Events