fmake field conditional

I have followed the below instructions for Using a server-side validator to set the Fix Versions required.

https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html#_using_a_server_side_validator_to_set_the_fix_versions_required

 

I couldn't achieved it fix version is not hidden when i gave resolution as except fixed.It is appearing all the time.

10 answers

This widget could not be displayed.

Hey Sarat!

Are you using the exact same code as in the example? Additionally, could you take a screenshot of your Behaviour's configuration and mapping and attach them here for me to take a look at? It may simply be that the condition:

if (resolution.name == "Fixed"){}

Isn't being returned as "true." So could you also take a screenshot of your resolution options? I've tested the code out myself and it works well, so it may be some instance-specific issue :D

Thanks!

Aidan

This widget could not be displayed.

Hi Sarat.

I think I gotcha.

Try this:

import static com.atlassian.jira.issue.IssueFieldConstants.FIX_FOR_VERSIONS
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

def resolution = getFieldById(RESOLUTION)
def version = getFieldById(FIX_FOR_VERSIONS)
if (resolution.getValue()?.name == "Fixed") {
version.setHidden(false)
version.setRequired(true)
}
else {
version.setHidden(true)
version.setRequired(false)
}

This is working perfectly in my instance as you can see below:

behaviour_hidden_fixedVersions.gif

If you have a problem. Please let me know.

If this answer solved your problem, please upvote it and mark it as answered. We also would love your feedback in our support revisions in the ScriptRunner Addon page.

Cheers!

DYelamos

This widget could not be displayed.

Yes, i have used same thing.When i used it cf1.setHidden(true) it is hidding the field but not performing the conditonal validation and show the field which is hidden in the step.

This widget could not be displayed.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil

// Get pointers to the custom field(s) required
def cf = getFieldByName("Affects Version/s")
def cf1 = getFieldByName("Fix Version/s")

// Get the Value of Affects Version/s
def cfVal = cf.getValue().toString()

// Hide Fix Version/s by default
cf1.setHidden(true)

 

after that it is not performing the conditionla validation.

 

if(cfVal == "AAE1")
{
cf1.setHidden(false)
}

This widget could not be displayed.

1.jpg2.jpg3.jpg

This widget could not be displayed.

Hey again Sarat!

I think the issue may just be that you need to attach that server-side script to the Resolution field instead of to an Initializer Function. The initializer function will only execute when the screen first appears and when the context is changed (from changing the issue-type of project).

Since you mentioned that the field is being hidden but never unhidden, I can only imagine that that is because the script is only running once and is never actually being re-run to check the conditional validation. But if you put the script on the Resolution field as a server-side script, it will run every time the Resolution field is changed.

Try that out instead and see if it works any better for you! :D Let me know what you find.

Best,

Aidan

This widget could not be displayed.

Hi Aidan,

 

added the server script to resolution filed now.

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.util.UserUtil

// Get pointers to the custom field(s) required
def cf = getFieldByName("Resolution")
def cf1 = getFieldByName("Fix Version/s")

// Get the Value of Resolution
def cfVal = cf.getValue().toString()

// Hide Fix Version/s by default
cf1.setHidden(true)

// If option Fixed is selected in Resolution show Fix Version/s and make it required
if(cfVal == "Fixed")
{
cf1.setHidden(false)
}
else
{
cf1.setHidden(true)
// Show Fix Version/s
cf1.setRequired(true) // Make Fix Version/s Required
}

 

 

what should i enter in Initialiser Function server script view?

Issues now:

If select resolution as anything it is showing up not hidden when the condition is not met. like resolution=fixed.

 

Please let me know your comments.4.jpg5.jpg6.jpg

 

 

This widget could not be displayed.

Hi 

DYelamos,

 

your script thrown error in the screen shot.so modified the line 6 to make error free script.

Modified script:

import static com.atlassian.jira.issue.IssueFieldConstants.FIX_FOR_VERSIONS
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

def resolution = getFieldById(RESOLUTION)
def version = getFieldById(FIX_FOR_VERSIONS)
if (resolution.getValue() == "Fixed") {
version.setHidden(false)
version.setRequired(true)}
else {
version.setHidden(true)
version.setRequired(false)
}

 

please let me know the solution to fix this issue.

 

Thanks,

Saratscript.jpg

Hello Ana.

To be honest I thought this was solved long ago, apologies for taking this long.

Regarding your error:

This is a Static type checking error.

Bottom line, it isn't a problem. Read this part of our documentation.

That explains why it isn't really an error.

Regarding your question:

I really don't understand why this isn't working for you.

For the sake of double checking I just tried to do this, this very morning. Works perfectly.

Refer back to my original step, and grab that very same code.

Then retrace my steps as follows:

  1. Create a new behaviour.
  2. Add the resolution field. This is not an initialise function.
  3. Add serverside script.
  4. Add the mapping to the relevant project/projects and issuetypes.

This, once again, works perfectly in our vanilla instances.

If it doesn't work for you, please post a full description of your instance:

  • Scriptrunner version
  • JIRA version
  • Behaviour screenshot
  • Field mapping of the behaviour.

Once I have all of that, I might be able to diagnose what is wrong with your instance.

Do you have a development instance that you could try this on? That might help.

Cheers

Dyelamos

This widget could not be displayed.

is there any update on my request.As it is show stopper for me.

 

Please respond asap.

 

Thanks,Sarat

Is there any solution to my issue?

 

thanks,

Sarat

This widget could not be displayed.

Hi,

I'm not getting what your saying.Fix version field disappears when i click on create issues screen.Please help me out to fix this issue.

 

Scriptrunner version 5.2.2
JIRA version 7.4.2

serverside script:

import static com.atlassian.jira.issue.IssueFieldConstants.FIX_FOR_VERSIONS
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

def resolution = getFieldById(RESOLUTION)
def version = getFieldById(FIX_FOR_VERSIONS)
if (resolution.getValue() == "Fixed") {
version.setHidden(false)
version.setRequired(true)
}
else {
version.setHidden(true)
version.setRequired(false)
}

 

p1.jpgp2.jpg

Sarah please do as I tell you:

Paste this script in your verification script box as is:

Do not modify anything

import static com.atlassian.jira.issue.IssueFieldConstants.FIX_FOR_VERSIONS
import static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTION

def resolution = getFieldById(RESOLUTION)
def version = getFieldById(FIX_FOR_VERSIONS)
if (resolution.getValue()?.name == "Fixed") {
version.setHidden(false)
version.setRequired(true)
}
else {
version.setHidden(true)
version.setRequired(false)
}

Do not mind the errors, they are static type checking errors, you can think of them as false positives. Just save the script with the errors. It should work.

Please if it doesn't let me know.

Cheers

DYelamos

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

115 views 2 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you