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,364,438
Community Members
 
Community Events
168
Community Groups

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

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

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

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

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

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

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

 

 

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

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

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.

Suggest an answer

Log in or Sign up to answer
TAGS

Atlassian Community Events