Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

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,552,579
Community Members
 
Community Events
184
Community Groups

Updating Fields dynamically in Jira Service Desk Portal with Scriptrunner

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.")

}

 

2 answers

2 accepted

1 vote
Answer accepted
Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jun 28, 2018

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

Снимок экрана 2018-06-28 в 20.11.40.png

 

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

Like Michael Smith likes this

Hi @Mark Markov

Thanks, but do you have any alternate suggestions

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 02, 2018

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

Hi @Mark Markov

Thanks but I had already tried this earlier, 

I have pasted code in Initialiser section under Behaviours. Attached Screenshot.

Behaviours_DescriptionChange.png

 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

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 03, 2018

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.

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

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 03, 2018

Ofcourse :

1. add your field

2. Add serverside script

image.png

Script that you attach to field will be run every time field value changes.

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

Mark Markov
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
Jul 03, 2018

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

Hi @Mark Markov

Thank you for all your help, I was able to achieve what i was looking for.

Appreciate it :)

0 votes
Answer accepted

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

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events