Script to replace Summary Field

I would like to know if there is a script so that I can replace the Summary field with two custom fields that the user fills in.

Scenario; user fills in the Issue Create form, and two of the custom fields (CF1 and CF2) now have data in them.

I would then like the script to run as a post function which then updates the Summary field with "CF1 relies on CF2" (for example)


Is this possible?

5 answers

1 accepted

Hi,

You can do it with javascript or with JJUPIN.

I thought you might be able to, but I have no scripting knowledge, so I was hoping someone would be able to help me write the script.

Hi,

In the configuration customfield issue type scheme, put this script in the description summary field to hide it (summary field )

<script type="text/javascript">

var summuryField=AJS.$("#summary").parent();

summuryField.hide();

</script>

And in the configuration customfield issue type scheme, put this script in the description of one of your custom field

For example ids of your custom fields are like this

CF1 id = customfield_xxxxx
CF2 id = customfield_yyyyy

We put this script in the description of CF2

<script type="text/javascript">

AJS.$('#customfield_xxxxx').keypress(function(){AJS.$('#summary').val(AJS.$("#customfield_xxxxx").val() + AJS.$("customfield_yyyyy ").val());})

</script>

This didn't work because the Summary field is set to Required, and I can't seem to un-required it.

Hi,

Set summary field value with a default value.

Add this script to summary descriptinon

<script type="text/javascript">
 
var summuryField=AJS.$("#summary").parent();
 AJS.$("#summary").val("default value");
summuryField.hide();
 
</script>

and you can use keyup

Ok, so the issue is now being raised, but the value of summary is coming through as "default value"

the CF ID's are:

CF1: 11327
CF2: 11320

The description of CF2 is:

<script type="text/javascript">
AJS.$('#customfield_11327').keypress(function(){AJS.$('#summary').val(AJS.$("#customfield_11327").val() + AJS.$("customfield_11320").val());})
</script>

Sorry for the late reply on this!

I've tried that but the same thing is happening.

CF_11327 - Radio Button called Status with two values (Active and Disabled)
CF_11320 - Text Field (< 255 characters) called Name

Yes, you can do it easily.

We do it using Kepler Rominfo's SIL custom field.

1) Get Kepler customfields from https://marketplace.atlassian.com/plugins/com.keplerrominfo.jira.plugins.keplercf

2) Create new SIL Script Custom Field for example mySILsummary

3) Enter configuration of the field

4) Click "Edit SIL Script"

5) Enter following code:

return customfield_11327 + " relies on " + customfield_11320;

6) In the post-function after issue creation just copy value from the mySILsummary to summary.

Voila.

We do it all the time with our issues, and it works like a charm :) SIL script field is really helpful every time you need a summary standarized in some way.

How do you get round the fact that the Summary field is on the screen and a required field?


I'd prefer if it wasn't visible to users, and didn't need them to interact with at all.

Yes, it is quite uncomfortable to must have the summary field on the creation screen. However, you can pre-fill it using Behaviours plugin.

In the administrative panel -> plugins -> Behaviours, add new mapping. Map to project and/or issue type you want. Than click "fields", select Summary field, and Add serverside script.

You can use similar one:

import com.atlassian.jira.issue.IssueFieldConstants
import java.util.List
import com.atlassian.crowd.embedded.api.User
import com.atlassian.jira.ComponentManager

User user = ComponentManager.getInstance().getJiraAuthenticationContext().getUser()
FormField formSummary = getFieldById("summary")
FormField formType = getFieldById("issuetype")

if (formType.getValue().contains("paste here number id of issue type"))
{formSummary.setFormValue("Your summary text")
}
else
{formSummary.setFormValue("")
}

This script will prefill summary only when you choose the required issue Type.

hi Ashley Powell,

you write a postfunction such that get the customfield values CF1 and CF2 from issue object.

Based on your requirement of customfield values set summary using the same issue object.

Finallu update issue and re-index.

You can check for workflow module postfunction.

How do you get round the fact that the Summary field is on the screen and a required field?
I'd prefer if it wasn't visible to users, and didn't need them to interact with at all.
Also, do you have any idea what this postscript would look like?

by default, summary field is required and go through the link

Also, the postfunction will be something like this:

import com.atlassian.jira.component.ComponentAccessor;

import com.atlassian.jira.issue.MutableIssue;

import com.atlassian.jira.issue.IssueManager;

import com.atlassian.jira.security.JiraAuthenticationContext;

MutableIssue issue=(MutableIssue)transientVariables.get("issue");

Object CF1 = issue.getCustomFieldValue(cfm.getCustomFieldObjectByName("Cus1"));

Object CF2 = issue.getCustomFieldValue(cfm.getCustomFieldObjectByName("Cus2"));

//some logic

if(CF1.toString().equals("x") && CF2.toString().equals("y")){

issue.setSummary("xy"+issue.getSummary());

}

try

{

IssueManager issueManager=ComponentAccessor.getIssueManager();

JiraAuthenticationContext authContext=ComponentAccessor.getJiraAuthenticationContext();

issueManager.updateIssue(authContext.getLoggedInUser(),issue,EventDispatchOption.ISSUE_UPDATED,true);

}

catch(Exception e){

e.printStackTrace();

}

you can try something like this

&lt;script type="text/javascript"&gt;
jQuery(document).ready(function($) {	
JIRA.bind(JIRA.Events.NEW_CONTENT_ADDED, function (e, context) {	
	addSummary();
});
addSummary();
function  addSummary(){		
		$('input:radio[name=customfield_11327]').click(function() {	
			AJS.$('#summary').val($('input[name=customfield_11327]:checked + label').text() + AJS.$('#customfield_11320').val());
		});	
		
	AJS.$('#customfield_11320').keyup(function(){
		AJS.$('#summary').val($('input[name=customfield_11327]:checked + label').text() + AJS.$('#customfield_11320').val());
		});

}
	
});
&lt;/script&gt;

i suggest load javascript as webresource module in a plugin

Works very Good. 

<script type="text/javascript">

AJS.$('#customfield_10009').keyup(

function(){AJS.$('#summary').val(AJS.$("#customfield_10101").val()+AJS.$("#customfield_10107").val()

);})

</script>

 

Result is: XXXXYYYYY

 

How do I get the Result: XXXX_YYYYY_Name of the Reporter ?


Thanks

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Julia Dillon
Posted Tuesday in Jira

Tell us how your team runs on Jira!

Hey Atlassian Community! Today we are launching a bunch of customer stories about the amazing work teams, like Dropbox and Twilio, are doing with Jira. You can check out the stories here. The thi...

231 views 1 18
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you