Forums

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

Sync b/w two fields

kk4065896 February 10, 2022

Hi All,

I have two custom fields called "cf1 and cf2" . The ask is make cf2 read only and it should update depending on cf1 single select options. Please help me to address this situation. I'm a new bee to the scripting part.

1 answer

1 accepted

0 votes
Answer accepted
Pramodh M
Community Champion
February 10, 2022

Hi @kk4065896 

With Behaviours in Scriptrunner!!

Example here

https://community.atlassian.com/t5/Jira-questions/Sync-between-two-fields-and-make-one-of-the-field-read-only/qaq-p/1941087

Another example is here

Define the Behaviour for fruits field and get the field ID of the field you need to make it as read-only, change the relevant options below

def fruits = getFieldById(getFieldChanged()).getValue().toString()
if (fruits == "Apple") {
getFieldById("customfield_10402").setFormValue("20 Rs");
}
else if (fruits == "Mango") {
getFieldById("customfield_10402").setFormValue("10 Rs");
}
else {
getFieldById("customfield_10402").setFormValue("5 Rs");
}

Let me know if you have any queries

Thanks,
Pramodh

kk4065896 February 11, 2022

@Pramodh M 

Thank you for sharing your answer and I tried to use the code but it is not working for me.

Here is the script what I used:

import com.atlassian.jira.issue.IssueFieldConstants
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours
def ManagerRole = getFieldById("customfield_10214")
def DeploymentState = getFieldById("customfield_11111")
if (ManagerRole == "None") {
getFieldById("customfield_11111").setFormValue("None");
}
else if (ManagerRole == "HR") {
getFieldById("customfield_11111").setFormValue("HR");
}
else if (ManagerRole == "A&Z") {
getFieldById("customfield_11111").setFormValue("A&Z");
}
else if (ManagerRole == "GA") {
getFieldById("customfield_11111").setFormValue("GA");
}
else if (ManagerRole == "T") {
getFieldById("customfield_11111").setFormValue("T");
}
else if (ManagerRole == "Dev") {
getFieldById("customfield_11111").setFormValue("Dev");
}
else if (ManagerRole == "Go") {
getFieldById("customfield_11111").setFormValue("Go");
}
else if (ManagerRole == "DI") {
getFieldById("customfield_11111").setFormValue("Unknown");
}
else if (ManagerRole == "New") {
getFieldById("customfield_11111").setFormValue("New");
}
else if (ManagerRole == "Unknown") {
getFieldById("customfield_11111").setFormValue("Unknown");
}
else if (ManagerRole == "CEO") {
getFieldById("customfield_11111").setFormValue("CEO");

Like Pramodh M likes this

Suggest an answer

Log in or Sign up to answer