Behaviour not working on Edit on single select value

Joel Batac September 12, 2022

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

2 accepted

0 votes
Answer accepted
Joel Batac September 14, 2022

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 = ''
}

0 votes
Answer accepted
Joel Batac September 12, 2022

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 = ''
}

0 votes
Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 12, 2022

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

Joel Batac September 12, 2022

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);
}

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 12, 2022

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

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

Joel Batac September 12, 2022

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

Joel Batac September 12, 2022

"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. 

Florian Bonniec
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 12, 2022

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