Hi,
I try to create an Automation to change value of a Custom Filed (Single Choice) in one Issue in Project A when File Attached in one Issue in Project B.
what method should I use to make it work? with Automation add-ons or Script Runner?Can you show me how to make it with Add-Ons or ScriptRunner?
Thanks
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.ComponentManager;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.IssueManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.search.SearchProvider;
import com.atlassian.jira.jql.parser.JqlQueryParser;
import com.atlassian.jira.web.bean.PagerFilter;
import com.atlassian.jira.issue.MutableIssue;
import com.atlassian.jira.issue.ModifiedValue;
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder;
//declaration
def issueManager = ComponentAccessor.getIssueManager();
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser)
def searchProvider = ComponentAccessor.getComponent(SearchProvider)
def user = ComponentAccessor.getJiraAuthenticationContext().getUser()
def judulCRQ = getFieldByName("Change ID");
def namaJudulCRQ = judulCRQ.getValue(); //isi field Change ID di CDR
// perform jql to get issue from dppqa
def query = jqlQueryParser.parseQuery("project = DPPQA and \"Nomor Change Request\" ~ ${namaJudulCRQ}")
def results = searchProvider.search(query, user, PagerFilter.getUnlimitedFilter())
log.debug("Total issues: ${results.total}")
if(results.total!=0){
results.getIssues().each {documentIssue ->
log.debug(documentIssue.key)
// if you need a mutable issue you can do:
def issue = issueManager.getIssueObject(documentIssue.id)
def targetCf = customFieldManager.getCustomFieldObject("customfield_10543") // DPPQA URS / KUS / Memo / MoM / E-mail / Incident ID / RMTM
def fptaCDR = customFieldManager.getCustomFieldObject("customfield_10951") // CDR FPTA File
def fptaQA = customFieldManager.getCustomFieldObject("customfield_10951") // DPPQA FPTA
// do something to the issue...
if (!getFieldByName("URS / KUS / Memo File").getValue()){
def changeHolder = new DefaultIssueChangeHolder()
// if File attached, changes DropDownList to "Sudah"
if(issue.setCustomFieldValue(targetCf, "Belum")){
getFieldByName("URS / KUS / Memo / MoM / E-mail / Incident ID / RMTM").setCustomFieldValue(targetCf, "Belum")
}else{
getFieldByName("URS / KUS / Memo / MoM / E-mail / Incident ID / RMTM").setCustomFieldValue(targetCf, "Sudah")
getFieldByName("URS / KUS / Memo File").setHelpText("Failed set on Issue Key ${issue.key} to \"Belum\" on ${targetCf}");
}
}
else{
issue.setCustomFieldValue(targetCf, "Sudah")
getFieldByName("URS / KUS / Memo File").setHelpText("Issue Name ${issue.summary} with ID ${issue.id} set \"Sudah\" on ${targetCf}");
}
}
}
and still get an error
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.