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

ScriptRunner update summary field upon user selection on issue screen

Hi,

I'm new to both Jira and ScriptRunner.  I'm trying to update summary field whenever user selects different value from custom field on issue screen.  Can  this be done?

I have tried with Behaviours but every example has "issue" which it doesn't work in Behaviours.

 

Thanks in advance!

2 answers

1 accepted

0 votes
Answer accepted
Deleted user Oct 22, 2019

Hi @Dong Park 

With Behaviour you can access the issue's data by using "underlyingIssue" instead.
Example:

underlyingIssue.getStatus()

You can set the summary field with this line of code:

getFieldById("summary").setFormValue("your summary here") 

 Hope this helps you on your way :)

 

Kind regards
Jorden

Thanks @[deleted] for your reply.

 

Here is what I have so far.

 

def cf = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10306")
def value = underlyingIssue.getCustomFieldValue(cf).toString()

This doesn't seem to work.  Here is my full code.

import com.atlassian.jira.component.ComponentAccessor


getFieldById("summary").setReadOnly(true)

def cf = ComponentAccessor.customFieldManager.getCustomFieldObject("customfield_10306")
def value = underlyingIssue.getCustomFieldValue(cf).toString()

def desc = getFieldById("summary")

def reporter = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def defaultValue = reporter.displayName
def fname = defaultValue.split(',')


if (! underlyingIssue?.description) {
desc.setFormValue(fname[1]+' '+fname[0])
}

 

There seems problem with "def value = underlyingIssue.getCustomFieldValue(cf).toString()"  because it doesn't populate anything to summary field.

But when I comment that line out, I do see my name in summary field.  

Deleted user Oct 23, 2019

Hi @Dong Park 

Problem here is (I think) that you are trying to get the stored value for the custom field, even though that's not yet passed to the database.

If you want to have your summary being filled in based on a value selected during the edit of the issue, you'll need to add a "server side script" to your field.

 

I created the following example: I have a select list called "Pending reason". The following script should be added as a server side script to that field to make sure that every time the field's value is changed, the summary is updated.

 

if (getFieldById(getFieldChanged()).value.toString() == "Awaiting approval")
{
getFieldById("summary").setFormValue("Issue awaiting approval")
}
else
{
getFieldById("summary").setFormValue("Issue not waiting approval")
}

Screenshot 2019-10-23 at 10.56.07.png 

Hope this helps!

Kind regards
Jorden

Deleted user Oct 23, 2019

PS: for other custom field value that are also available on the screen, use

getFieldById(customfield_XXXX).value.toString()

Kind regards
Jorden 

This method works.

 

Here is my code to make it work for my drop down selection.

 

def fromField = getFieldById(getFieldChanged())
def summaryField = getFieldById("summary")
def from = fromField.getValue()

summaryField.setFormValue(from)
Like Deleted user likes this
0 votes
Leo Community Leader Oct 22, 2019

Hi @Dong Park

You can use below snippet to fetch custom field's data in behaviour

def cf = getFieldByName("Custom Field Name")
def value = cf.getFormValue()

 The known result is behavior will fetch field's data(which is filled during the screen/form loads) if the data/value changes after screen pop up behavior script won't re-run and change your target field value based on condition

 

you can achieve this in two ways

1. Add post-function in create transition and validate your field values based on that update/modify default summary of the ticket(only during create action)

sample snippet is below for post-function event

import com.atlassian.jira.component.ComponentAccessor

def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Custom Field Name Not ID")
def value = issue.getCustomFieldValue(cf)

if(value == "testing"){
issue.setSummary("summary for testing value")
}
else{
issue.setSummary("summary for others")
}

2. If you want to update summary whenever custom field is getting changed you can go with custom listener(but it's advisable not to change your summary often)

 

BR,

Leo

Thanks @Leo 

def cf = getFieldByName("Custom Field Name")
def value = cf.getFormValue()

I understand this works only when the value gets populated during the load but giving me "null" value even though I set the default value in text field. 

My goal here is to dynamically change the summary field when user changes the value on issue screen.  From you post, I take only way to do this is to do it from "custom listener"?  Or this can't be done from issue screen? 

Leo Community Leader Oct 22, 2019

Hi, 

If you want to go with dynamic updates in screen view. you'll have to choose with javascript

you'll have to place your javascript in the description of field on which you want dynamic change

maybe Field configuration--> Summary --> Edit(script in description)

I never tried field update through javascript, below snippet may help you in fetch field data there. this is just enable/disable field based on another field value

 

<script type="text/javascript">

 priority = document.getElementById('priority');

  if (priority) {

      target = document.getElementById('customfield_10000');

      // Hide the target field if priority isn't critical

      if (priority.value != 10005) target.style.display='none';

      priority.onchange=function() {     

          console.log("This value is: " + this.value);

          if (this.value == 10005) {             

                     target.style.display = ''; 

                     target.value="Please input Business Impact";

           }else {

                 target.style.display='none';

          }

      }

  }

 </script>

 

If your goal is to set summary value based on some criteria, I would suggest you to with post-function

create some default text as summary value, while submitting validate field values and set summary accordingly. while you see the created issue summary will be updated based on your condition

 

BR,

Leo

Leo Community Leader Oct 22, 2019

@Dong Park

I tweaked the javascript to update summary field, below snippet will change summary dynamically on priority field change. hope it helps you

(NOTE: you must place this script in summary field description)

</script>

<script type="text/javascript">

priority = document.getElementById('priority');

if (priority) {

if (priority.value == 1) {
AJS.$("#summary").val("Summary for Blocker");
}else{
AJS.$("#summary").val("Summary for others");
}
priority.onchange=function() {

if (priority.value == 1) {
AJS.$("#summary").val("Summary for Blocker");
}else{
AJS.$("#summary").val("Summary for others");
}

}

}

</script>

 

BR,

Leo

Thanks so much @Leo

I think this would be a good starter point.  I'll work on it this week and will follow up on it.

Thanks again! :)

Deleted user Oct 23, 2019

Hi

I strongly recommend using Behaviours if you have the ScriptRunner plugin rather than adding javascript in the custom field's description. It's just harder to keep track of and I don't think it's actually supported.

Kind regards
Jorden

Deleted user Oct 23, 2019

Woops didn't read you wanted in the 'view' screen.

That's not possible with behaviours. I guess you could do it with javascript in that case, but still try to avoid javascript in descriptions whenever possible :D

@[deleted] 

Yes my goal is to have user to select from drop down or check boxes and populate the data to summary field or the description field so that the format would be exactly the same for every ticket.  And at the same time I want user to see the data populated to the field. 

 

Thanks everyone though! :)

@Dong Park did you manage to solve your problem?
We are facing the same need !

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Jira Service Management

JSM June Challenge #2: Share how your business teams became ITSM rockstars

For JSM June Challenge #2, share how your non-technical teams like HR, legal, marketing, finance, and beyond started using Jira Service Management! Tell us: Did they ask to start using it or...

326 views 9 7
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