Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,365,417
Community Members
 
Community Events
168
Community Groups

Behaviour not working on Edit on single select value

Hi,

 Need help with behaviour. Below is my code, basically it sets the RL value based on the screen used. It work when creating but when editing, it should make API mandatory if the current value of RL does not contains L6

RL is a single select field. API is Element connect field.

///INITIALLIZER
import com.atlassian.jira.component.ComponentAccessor;
def RL = getFieldById("customfield_26800")
def PI = getFieldById("customfield_27801")
def RLCurrentValue


PI.setAllowInlineEdit(false)
RL.setAllowInlineEdit(false)

///sets RL CF Value based on the screen used
if (getFieldScreen().name == ("Projecte Template 1 - Initiative Screen")){
RL.setFormValue('11905')
RL.setHidden(false);
PI.setFormValue('');
PI.setHidden(true);
PI.setFormValue('');


} else if (getFieldScreen().name == ("Projecte Template 2 - Initiative Screen")) {
RL.setFormValue('')
RL.setRequired(true);
PI.setFormValue('');
PI.setHidden(true);
PI.setRequired(false);
}


///retain RL values if there's existing
if(underlyingIssue){

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(underlyingIssue).find{it.name == RL}
RLCurrentValue = underlyingIssue.getCustomFieldValue(cf)
} else {
RLCurrentValue = ''
}

 


///MAIN CODE
import com.atlassian.jira.component.ComponentAccessor;

def RL = getFieldById("customfield_26800")
def PI = getFieldById("customfield_27801")
def RLValue = RL.getValue() as String

PI.setAllowInlineEdit(false)
RL.setAllowInlineEdit(false)
//selectField.allowInlineEdit(false)

if (RLValue.contains("L6")) {
PI.setFormValue('');
PI.setHidden(true);
PI.setRequired(false);
} else {
//PI.setFormValue('');
PI.setHidden(false);
PI.setRequired(true);
}



3 answers

Update: I got this working.  Just need the below code on top of the Initializer

///retain RL values if there's existing
if(underlyingIssue){

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(underlyingIssue).find{it.name == RL}
RLCurrentValue = underlyingIssue.getCustomFieldValue(cf)
} else {
RLCurrentValue = ''
}

Update: Just need this lines of codes on top of initialilzer

///retain RL values if there's existing
if(underlyingIssue){

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjects(underlyingIssue).find{it.name == RL}
RLCurrentValue = underlyingIssue.getCustomFieldValue(cf)
} else {
RLCurrentValue = ''
}

Hi

 

Do you have any condition in your behaviours ?

Are you sure the condition you have in your script works ? If it's not working that means that it's either not executed or it do not behave as expected.

You want to clear PI value when RL value is set also ?

 

Can you add a simple 

 

 getFieldById("summary").setDescription("THis is a test")

 

Just to be sure if the script if executed ?

Regards

Yes it works when creating. It's just when editing the condition doesn't work. You have to 'trigger' it to work, meaning select anything but the current RL value and it works.

But if you don't change the RL value (let's say currently it's L1) you will be able to remove the API value since it's not setting as mandatory. This is my main concern. 

 

Below is the code used for setting fields behaviour 

if (RLValue.contains("L6")) {
PI.setFormValue('');
PI.setHidden(true);
PI.setRequired(false);
} else {
PI.setHidden(false);
PI.setRequired(true);
}

Code in the Initiator should be trigger when loading any screen.

Did you set this code in the Initator or somewhere else ?

Yes, it sets the default value of RL to L6 (RL.setFormValue('11905')) or empty, depending on the screen used. 

No, only on the RL field behavior

"You want to clear PI value when RL value is set also ?"  --- no, i want PI to be mandatory if RL does not contain L6 during Editing. 

You have to set this piece of code in the Iniator part as well if you want it to be executed when the screen is displayed without having to click on the field to trigger the script.

Suggest an answer

Log in or Sign up to answer