I have a workflow designed, and when it is clicked on the issue screen, it pops this window.
def log = Logger.getLogger("com.onresolve.scriptrunner.runner.ScriptRunnerImpl")
log.setLevel(Level.DEBUG)
def issueManager = ComponentAccessor.issueManager
//def issue_key="TM-636" //for testing purpose only
//def issue_obj = issueManager.getIssueObject(issue_key) // for testing purpose only
def issue_key=issue
def issue_obj = issueManager.getIssueObject(issue.toString())
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def cField = customFieldManager.getCustomFieldObject("customfield_10501") //Custom Field Value - object TM_confirm_21,
def owner=issue_obj.getReporter();
ownerName=owner.getName();
def json = issue_obj.getCustomFieldValue(cField)
log.info(json)
ArrayList<String> questionList = new ArrayList();
ArrayList<String> answerList = new ArrayList();
String[] arr = json.split("fields\":");
System.out.println(arr.length);
for (String string : arr) {
String[] a = string.split("value\":");
for (String string1 : a) {
if (string1.startsWith("\"")) {
String content = string1.substring(1, string1.indexOf("\"}"));
if (content.equals("0396bc37-942d-4e7e-bd53-e77d8ae1d5c9")) {//yes id
answerList.add("Yes");//yes
} else if (content.equals("b0ff8ab7-7038-496c-bea7-05a46252847f")) {//no id
//no
answerList.add("No");
} else {
questionList.add(content);
}
}
}
}
HashMap<String, String> finalMap = new HashMap();
for (int i = 0; i < answerList.size(); i++) {
if (!answerList.get(i).equals("Yes")) {
finalMap.put(questionList.get(i), answerList.get(i));
}
}
for (Map.Entry<String, String> entry : finalMap.entrySet()) {
Object key = entry.getKey();
Object val = entry.getValue();
log.info("asad "+key.replace("\\n","\\\\n"))
log.info(val)
}
def authString = "username:password".getBytes().encodeBase64().toString()
int counter=0;
for (Map.Entry<String, String> entry : finalMap.entrySet()) {
counter+=1;
log.info("Counter "+counter)
String question="Security weakness identified in Threat Modeling. You can use the technical details below to address the weakness in technical design.\\n"
question += entry.getKey();
Object val = entry.getValue();
//question=question.replace("\\n", "\\r\\n");// new line character to encode for json
log.info("question: "+question)
def createSubTaskBody="{\"fields\":{\"project\":{\"key\": \"TM\"},\"parent\":{\"key\": \""+issue_key+"\"},\"summary\": \""+issue_key+"- Security Task ["+counter+"]\",\"description\": \""+question+"\",\"issuetype\":{\"id\": \"10003\"},\"assignee\":{\"name\":\""+ownerName+"\"}}}"
log.info(createSubTaskBody)
connection1.setRequestMethod( "POST" )
connection1.setRequestProperty( "Authorization", "Basic ${authString}" )
connection1.doOutput = true
connection1.setRequestProperty("Content-Type", "application/json;charset=UTF-8")
connection1.getOutputStream().write(createSubTaskBody.getBytes("UTF-8"))
connection1.connect()
def postRC2 = connection1.getResponseCode();
if(postRC2==201)log.info("created successfully ") else log.info("Error creating sub-task "+postRC2)
//log.info(issue_key)
}
What this code does is explained here:
When I click the Complete Threat Modelling button mentioned as 1, it fetches the current value of Field mentioned as 2.
It then opens the following screen where I can change the answers to the question:
I am unable to get why the scripts behave this way.