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);
}
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 = ''
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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);
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Code in the Initiator should be trigger when loading any screen.
Did you set this code in the Initator or somewhere else ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
"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 must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.