I need help with this script post function

Hi,


I have this script post function:

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.component.ComponentAccessor


ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

def optionsManager = ComponentAccessor.getOptionsManager()

CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Major incident"}
CustomField commentYes = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Comment MI"}

fieldConfig = commentYes.getRelevantConfig(issue)
newValue = optionsManager.getOptions(fieldConfig)?.find{it.value == "Yes"}
oldValue = optionsManager.getOptions(fieldConfig)?.find{it.value == "No"}

cfwt = issue.getCustomFieldValue(srcField).getValue()

log.debug("Major Incident value: $cfwt")
//If CustomField 'Major incident == TRUE

if (cfwt == "TRUE"){
            //TODO HERE!!
}

I want to if 'cfwt == "TRUE"' do following things:

1) Make a comment in issue with another user that is not my current user.

2) This comment have to have visibility coment to a specific project role.


Is possible do this with script post function?

Thanks in advance,

Daniel

2 answers

1 accepted

This widget could not be displayed.

to comment

CommentManager commentMgr = ComponentAccessor.getCommentManager();
commentMgr.create(issue, "username", "comment body","groupLevel","roleLevelId", false/true);

This widget could not be displayed.

Thanks, this works for me!

I put my script post function code for everyone will implement a similar script like me :

import com.atlassian.jira.ComponentManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.fields.CustomField
import com.atlassian.jira.issue.comments.CommentManager
import com.atlassian.jira.component.ComponentAccessor

ComponentManager componentManager = ComponentManager.getInstance()
CustomFieldManager customFieldManager = componentManager.getCustomFieldManager()

CommentManager commentMgr = ComponentAccessor.getCommentManager();

def optionsManager = ComponentAccessor.getOptionsManager()

CustomField srcField = customFieldManager.getCustomFieldObjects(issue).find {it.name == "Major incident"}

cfwt = issue.getCustomFieldValue(srcField).getValue()

//log.debug("Major Incident value: $cfwt")

if (cfwt == "TRUE"){
  commentMgr.create(issue, "support", "Message Comment", null, 10200, false);
}


Best regards,

Daniel

Suggest an answer

Log in or Sign up to answer
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

161 views 2 0
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