Custom Script Field: Return the characters at the positions specified from Summary field.

Megan D March 22, 2024

Hello,

In our Summaries, there is an internal number in this format:

AAA-B-CC-DD-EEEE-FFF-XXXX-G

I need to create a custom scripted field that returns the four X's toward the end. I know I need to use a substring to return characters 21-25 of that string. Like this:

substring(21,25)

...Which should show just the XXXX in the custom field.

However, I don't know how to call up the Summary and code that whole thing. Can anyone help me? Thank you!

1 answer

1 accepted

2 votes
Answer accepted
Megan D March 22, 2024

Well, that was easier than expected. I have figured it out only moments after post, but maybe this will help someone.

issue.summary.substring(21,25)
ramyaallena
Contributor
April 12, 2024

Hi @Megan,

Could you please share all of the code you used to achieve this? 

Or the procedure you used.

That helps me understand how the scripted field has been created.

Thanks,

Allena

Megan D April 12, 2024

Hi @ramyaallena ,

Sure. I'm using Jira Server with the 8.19.1 version of the software.

The steps to accomplish this were:

  1. Click the cog in the upper right next to your profile picture.
  2. Select Manage Apps from the drop down.
  3. On the left-hand column of the next page, go to Fields
  4. Click the blue button in upper right of that section called "Create Script Field"
  5. Pick "Custom Script Field" from the option list.
  6. Fill in what you want to name the field and pick "Text Field (multi-line)"
  7. In the Script area, enter:
    1. issue.summary.substring(#,#)
    2. Where "summary" is the field name. So replace that with your own field if you want - though not sure how that works with custom fields. You could try this but I'm not an expert:
      1. ${issue.getcustomField(com.atlassian.jira.component.ComponentAccessor.getCustomFieldManager().getCustomFieldObject(CUSTOMFIELDNUMBER)).substring(#,#)}
    3. The #'s represent the number of the characters from the left of the phrase. This includes any spaces or symbols. So for mine, I wanted the script to capture characters 21 through 25.
  8. Press Update and the field should be added to your issues. Keep in mind it will not show on editable screens (since it is auto-generated), but will show on the view mode.
  9. Back in the Fields section, make sure you assign your configure the contexts of which projects you want the field to show up in.

Hopefully that helps.

 

ramyaallena
Contributor
April 12, 2024

That's great  @Megan D ,

thanks for all the detailed explanation.

 

-Allena

Megan D April 15, 2024

You are welcome =) Hopefully that worked for your purposes.

Suggest an answer

Log in or Sign up to answer