I have a drop down with two options and I want to hide some custom required fields when one of the options is selected. The problem is that when I hide a field it stays required. So i cant complete issue creaton.
const customDateField = getFieldById("customfield_10062");
const dropDown= getFieldById("customfield_10059");
if(dropDown.getValue().value == 'option1'){
customDateField.setRequired(false);
customDateField.setVisible(false);
}else{
customDateField.setVisible(true);
customDateField.setRequired(true);
}
So the natural thing for me was to set the field required to false when I hide it but then I get the error:
Uncaught Error: UIM tried to set an invalid value for "isRequired" property on a field (fieldId: "customfield_10062", fieldType: "com.atlassian.jira.plugin.system.customfieldtypes:datepicker")
Can someone help me?
Hi @Relja Mihajlovic and thanks for your question.
Can you try this code please,
const customDateField = getFieldById("customfield_10062");
const dropDown= getFieldById("customfield_10059");
if(dropDown.getValue().value == 'option1'){
customDateField.setRequired(false);
customDateField.setVisible(false);
}else{
customDateField.setVisible(true);
customDateField.setRequired(true);
}
I tested the case you mentioned in my own environment and I see that it's working properly. You might have called the name you used in your definition incorrectly. If the issue persists, please provide further feedback.
Best,
Murat Seven
Thank you for pointing that out but as i replayed to @Tansu Akdeniz i edited the code variable names to post it here and forgot to change that to dropDown.
Do you know what could be the problem since its not that?
When i remove these two lines
customDateField.setRequired(false);
customDateField.setRequired(true);
Code works fine, fields get hidden. But when i try to setRequired it gives me the error?
Maybe its because my custom fields are pre setup as required?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Are you using the 'required' action with field configuration? I think instead of required custom fields, you should set this in the behavior script using 'setRequired.' Could you try it this way?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Yea i was using 'required' action with field configuration, now it works, thank you @Murat Seven . <3
But it kind of defeats the purpose?
Now I need to add every project to behaviour mapping (Script Runner) that I want this field to be required.
Is there a way to make this custom filed required (with field configuration) for some projects and for some not?
I guess that's where Field Configuration Schemes come into play?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I'm glad I could help :)
Yes @Relja Mihajlovic , configuring whether a specific custom field is required for certain projects is typically achievable using Field Configuration Schemes. These schemes determine how specific fields behave for particular projects.
Hope this helps.
Best,
Murat
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I assume you require fields via Behaviours (not jira fields config scheme).
I can't see tipDokumenta definition in your script.
Could you please check the return value below?
tipDokumenta.getValue()
You can also use formField.setHelpText(helpText) to see the value on screen as a debugging purpose.
Please take a look at this: API Quick Reference
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Sorry forgot to change that. I edited the code to poste it here and forgot to change the name of the variable.
So that part is good.
I will fix my post. Thank you for pointing that out to me.
Do you know what could be the problem since its not that?
When i remove these two lines
customDateField.setRequired(false);
customDateField.setRequired(true);
Code works fine, fields get hidden. But when i try to setRequired it gives me the error?
Maybe its because my custom fields are pre setup as required?
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.