I have tried many of the examples for updating fields, but none of them seem to work.
I want to update any field based on another selected, in the portal form front end. Is this possible ? As the links below seem to mention how to do it, but it doesnt work practically
https://scriptrunner.adaptavist.com/latest/jira/behaviours-servicedesk.html
https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/select-list-other.html
---------
def desc = getFieldById("description")
def regressionIssueField = getFieldById(getFieldChanged())
if (regressionIssueField == "priority") {
desc.setFormValue("defaultValue")
}
---------------
import com.onresolve.jira.groovy.user.FieldBehaviours
import com.onresolve.jira.groovy.user.FormField
import groovy.transform.BaseScript
import com.atlassian.jira.config.PriorityManager
import com.atlassian.jira.issue.priority.Priority
@BaseScript FieldBehaviours fieldBehaviours
if ((getFieldById(getFieldChanged()).value as Priority)?.name == "High") {
getFieldById("description")
.setLabel("Why do you need this and why so important?")
.setDescription("Please explain why this is Highest priority including details of outage etc.")
}
else {
getFieldById("description")
.setLabel("Why do you need this?")
.setDescription("Tell us why you want this.")
}
Hello @rakshith
And welcome to the community.
I check both scripts. First one have an error (i think), second one works perfectly.
So, first thing to check is that your behaviour correctly mapped to service desk like this
And second thing is that in your first script in your condition compared value and formfield object, it must be like this:
def desc = getFieldById("description")
def regressionIssueField = getFieldById(getFieldChanged())
if (regressionIssueField.value == "priority") {
desc.setFormValue("defaultValue")
}
Hope it helps!
Hi Mark, Thanks for reply
I had set the mapping already.
Also regressionIssueField.value is the value, i.e. High, Medium, Low not actual priority
Do you have any other suggestions.
Is ScriptRunner actually able to dynamically update front end UI fields, or is ther any other tool
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.
Hi @rakshith
Sorry for a long reply. As i understand, you need to set description based on regressionIssueField value, am i right?
Yes, Scriptrunner able to update fields values dynamically.
Try this
def desc = getFieldById("description")
def regressionIssueField = getFieldById(getFieldChanged())
if (regressionIssueField.value == "High") {
desc.setFormValue("defaultValue for High")
}
if (regressionIssueField.value == "Low") {
desc.setFormValue("defaultValue for Low")
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Markov
Thanks but I had already tried this earlier,
I have pasted code in Initialiser section under Behaviours. Attached Screenshot.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Markov
I can pre-populate the description or any other field infact, during page load.
def desc = getFieldById("description")
def defaultValue = "Test value"
desc.setFormValue(defaultValue)
But I am not able to dynamically change values once the page is already loaded. Is there any other event firing method available other than getFieldChanged(). As this doesnt seem to work. Im using Jira v7.5.0
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Oh, that will not work. Initialiser function runs only once when form loads. It uses for setting form defaults only. If you want to change dynamically based on some field value, you need add that field in the section bellow initialiser (in your case it will be regressionIssueField), and place you code to that field.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hey @Mark Markov
can you tell me where I need to add the script, the only other option I see is "Add server-side script" and that doesnt work.
Where is this location " you need add that field in the section bellow initialiser (in your case it will be regressionIssueField), and place you code to that field."
Can you post a screengrab or other detail of how I can use this
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ofcourse :
1. add your field
2. Add serverside script
Script that you attach to field will be run every time field value changes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks @Mark Markov but I had added in Server side script too, it didnt work.
Also I feel usually its client side script that we need to add, like javascript or other which renders front end changes.
The ScriptRunner documentation is not clear on this, can you pls advice if you know anything further
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Actually behaviours javascript-based and renders frontend changes. But partly.
When form is loaded, behaviour catch this changes, runs code you wrote(on server side), make some magic, and returns final javascrpit thats performs on client side after form loaded.
Thats why "Add server-side script" misleading you. It's sctill client-side and javascript based
ref
https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html#_limitations
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Markov
Thank you for all your help, I was able to achieve what i was looking for.
Appreciate it :)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Mark Markov
I used different code to get field changed, and that seemed to work in the server side script
if ((getFieldById(getFieldChanged()).value as Priority)?.name == "High") {
ill keep you updated if it all works
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.