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.
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
Thanks!
Aidan
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.ComponentAccessorimport com.atlassian.jira.user.util.UserUtil// Get pointers to the custom field(s) requireddef cf = getFieldByName("Affects Version/s")def cf1 = getFieldByName("Fix Version/s")
// Get the Value of Affects Version/sdef cfVal = cf.getValue().toString()
// Hide Fix Version/s by defaultcf1.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! Let me know what you find.
Best,
Hi Aidan,
added the server script to resolution filed now.
import com.atlassian.jira.component.ComponentAccessorimport com.atlassian.jira.user.util.UserUtil// Get pointers to the custom field(s) requireddef cf = getFieldByName("Resolution")def cf1 = getFieldByName("Fix Version/s")
// Get the Value of Resolutiondef cfVal = cf.getValue().toString()
// If option Fixed is selected in Resolution show Fix Version/s and make it requiredif(cfVal == "Fixed"){cf1.setHidden(false)}else{cf1.setHidden(true)// Show Fix Version/scf1.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.
Hi Sarat.
I think I gotcha.
Try this:
import static com.atlassian.jira.issue.IssueFieldConstants.FIX_FOR_VERSIONSimport static com.atlassian.jira.issue.IssueFieldConstants.RESOLUTIONdef 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:
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
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_VERSIONSimport 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,
Sarat
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,
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:
This, once again, works perfectly in our vanilla instances.
If it doesn't work for you, please post a full description of your instance:
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,
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.2JIRA version 7.4.2
serverside script:
Sarah please do as I tell you:
Paste this script in your verification script box as is:
Do not modify anything
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.
It looks like you're new here. Sign in or register to get started.