Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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.

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

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

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

 

 

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

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,

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
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Why everyone using Jira must be GDPR-compliant

Did you know that penalties up to 4 % of the yearly company turnover are possible in case of GDPR violations? GDPR regulations are currently mainly relevant for companies in the EU, but countries lik...

81 views 1 2
Read article

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you