condition "project" for postfunction Set Field Value to constant

Hallo,

I want to execute a postfunction "Set Field Value to constant" in dependence of in which project the issue is created.

How to do this? (I have tried something but nothing works)

 

image2016-6-14 14:56:40.png

 

Thanks a lot.

Tatjana

4 answers

0 vote
Mahesh S Community Champion Jun 14, 2016

My understanding is, you need a post function to set this custom field value based on the project name. For example, if project name is 'abc', then the field alfrageteilnehmer has to be set as 'tg'. Am I right?

If not please explain.

That's right, that's what I'm want.

0 vote
Mahesh S Community Champion Jun 14, 2016

Please try this and let me know the results.

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.util.ImportUtils
import com.atlassian.jira.user.util.DefaultUserManager
import com.atlassian.crowd.embedded.api.User
 
	IssueManager issueManager = ComponentAccessor.getIssueManager()
	CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager()
	CustomField myCustomfield = 	customFieldManager.getCustomFieldObjectByName("alfrageteilnehmer")
	
	if(issue.getProjectObject().getKey() == 'ABC'){
	myCustomfield.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(myCustomfield), "tg"),changeHolder);
	}

This code doesn't work, bev´cause the expression have to retun "true".

You have to do it this way.

image2016-6-15 11:25:29.png

It works, thank you very very much. Your post was the hint I needed to finde the solution.

 

 

Mahesh S Community Champion Jun 15, 2016

Glad that it worked. That script I had shared will work directly to set the field value via a scripted post function (instead of returning a true boolean value for a condition in a built-in post function.) However, you made it work for the second scenario. Congrats! smile

Mahesh S Community Champion Jun 15, 2016

To be more precise, I was checking the project name and setting the field value on my own in the script. It works in the scripted post function option.

No sorry, it doesn't work. The function must return 'true'

 

image2016-6-15 8:37:41.png

 

I've tried to return true, but doesn't work, don't understand what to do here.

Suggest an answer

Log in or Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,319 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot