// Get a pointer to the Linked Issues Text Area
//def linkedIssuesCF = getFieldById("issuelinks")
import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat;
def issueManager = ComponentAccessor.getIssueManager()
Date latest_begin_date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Calendar cal = Calendar.getInstance();
def linkedIssuesCF = getFieldById(getFieldChanged())
def issueLinksCF = getFieldById("issuelinks-linktype")
def linkedIssueForm = getFieldById("issuelinks-issues")
if ( issueLinksCF.getValue().toString() == "is blocked by" ) {
List <String> keys = linkedIssueForm.getValue()
for ( key in keys) {
def linkedIssue = issueManager.getIssueObject(key.toString())
if ( linkedIssue.dueDate.after(latest_begin_date) ){
latest_begin_date = linkedIssue.dueDate
}
def begin_date = getFieldByName("Begin Date")
cal.setTime(latest_begin_date);
cal.add(Calendar.DATE,1)
begin_date.setFormValue(cal.getTime())
}
}
but i can't not fetch issuekey via the statement:
linkedIssueForm.getValue()
finally, the code block as follow is work.
List keys = []
import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat;
def issueManager = ComponentAccessor.getIssueManager()
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Calendar cal = Calendar.getInstance();
def linkedIssuesCF = getFieldById(getFieldChanged())
def issueLinksCF = getFieldById("issuelinks-linktype")
def linkedIssueForm = getFieldById("issuelinks-issues")
if ( issueLinksCF.getValue().toString() == "is blocked by" ) {
if ( linkedIssueForm.getValue() instanceof java.util.List ) {
keys = ((String[])linkedIssueForm.getValue()).toList()
}else{
if (linkedIssueForm.getValue()) {
keys += (String)linkedIssueForm.getValue()
}
}
if ( ! keys.isEmpty() ) {
//linkedIssueForm.setError("keys is not empty!")
def latest_begin_date = sdf.parse(sdf.format(cal.getTime()))
for ( String key in keys) {
//linkedIssueForm.setError(key)
def linkedIssue = issueManager.getIssueObject(key)
if (! linkedIssue ) {
continue
}
if (! linkedIssue.dueDate ) {
continue
}
if ( linkedIssue.dueDate.after(latest_begin_date) ){
latest_begin_date = linkedIssue.dueDate
}
}
def begin_date = getFieldByName("Begin Date")
SimpleDateFormat sdf_begin = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
SimpleDateFormat sdf_date = new SimpleDateFormat("yyyy-MM-dd");
cal.setTime(sdf_begin.parse(sdf_date.format(latest_begin_date) +" 23:59:59"));
cal.add(Calendar.SECOND,1)
//begin_date.setError(sdf_begin.format(cal.getTime())+" "+cal.get(Calendar.DAY_OF_WEEK).toString())
if(cal.get(Calendar.DAY_OF_WEEK) == 7 ){
cal.add(Calendar.DATE,2)
}else if(cal.get(Calendar.DAY_OF_WEEK) == 0){
cal.add(Calendar.DATE,1)
}
begin_date.setFormValue(sdf_date.format(cal.getTime()))
}
}
Hello @echo lee
This is happens because issuelinks is empty on form.
If you want get linked issues of current Issue, you ll need to use IssueLinkManager
It should be like this
// Get a pointer to the Linked Issues Text Area
//def linkedIssuesCF = getFieldById("issuelinks")
import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat;
Date latest_begin_date = new Date();
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Calendar cal = Calendar.getInstance();
def linkedIssuesCF = getFieldById(getFieldChanged())
def issueLinkManager = ComponentAccessor.getIssueLinkManager()
def linkedIssues = issueLinkManager.getOutwardLinks(underlyingIssue.id).findAll {it.issueLinkType.name.equalsIgnoreCase("is blocked by")}.collect {it.getDestinationObject()}
if (linkedIssues) {
for ( linkedIssue in linkedIssues) {
if ( linkedIssue.dueDate.after(latest_begin_date) ){
latest_begin_date = linkedIssue.dueDate
}
def begin_date = getFieldByName("Begin Date")
cal.setTime(latest_begin_date);
cal.add(Calendar.DATE,1)
begin_date.setFormValue(cal.getTime())
}
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hello @Mark Markov
thanks for your suggestion.
but i will using this script to provide my end user with a pre-filled date value based on the linked issue, when they add the issues to the form issuelinks‘s field issuelinks-issues, and the linktype is "is blocked by"
i found that, when i add one issue to the form,
(String)linkedIssueForm.getValue() can return the issuekey, but when i add two issues to the form, linkedIssueForm.getValue() return a list, and i can't do with the list.
the modified code block as follow:
if (getAction()?.id != 1) {
return // not the initial action, so don't set default values
}
List keys = []
import com.atlassian.jira.component.ComponentAccessor
import java.text.SimpleDateFormat;
def issueManager = ComponentAccessor.getIssueManager()
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
Calendar cal = Calendar.getInstance();
def linkedIssuesCF = getFieldById(getFieldChanged())
def issueLinksCF = getFieldById("issuelinks-linktype")
def linkedIssueForm = getFieldById("issuelinks-issues")
if ( issueLinksCF.getValue().toString() == "is blocked by" ) {
Date latest_begin_date = new Date();
if ( linkedIssueForm.getValue().getClass().isArray() ) {
keys = ((String[])linkedIssueForm.getValue()).toList()
}else{
keys += (String)linkedIssueForm.getValue()
}
for ( String key in keys) {
linkedIssueForm.setError(key)
def linkedIssue = issueManager.getIssueObject(key)
if (! linkedIssue ) {
continue
}
if (! linkedIssue.dueDate ) {
continue
}
if ( linkedIssue.dueDate.after(latest_begin_date) ){
latest_begin_date = linkedIssue.dueDate
}
}
def begin_date = getFieldByName("Begin Date")
cal.setTime(latest_begin_date);
cal.add(Calendar.DATE,1)
begin_date.setFormValue(cal.getTime())
}
the code block as follow can't work.
if ( linkedIssueForm.getValue().getClass().isArray() ) {
keys = ((String[])linkedIssueForm.getValue()).toList()
}else{
keys += (String)linkedIssueForm.getValue()
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @echo lee,
Do you want to provide your end user with a pre-filled date value based on the linked issue that they can change when editing the issue?
If so, you might want to make use of the underlyingissue (see https://community.atlassian.com/t5/Adaptavist-questions/ScriptRunner-Behaviours-how-to-get-information-of-an-issue-when/qaq-p/625146 for an example), to get the issue object. Starting with that one, you can just fetch all the information using the Jira api instead of parsing values from the form.
Other question:
- Do you use this block as a behaviour validator or an initialiser?
- Is it an option to provide a script listener that will automatically fill in those values upon updating the issue?
Kind regards,
Tom
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Tom.
yes, i want to provide my end user with a pre-filled begin_date based on the linked issue , when they add the linked issues.
if there are linktype 'is blocked by" issues exists, begin_date = blockissues's latest_duedate + 1
otherwise, begin_date is today.
- Do you use this block as a behaviour validator or an initialiser?
i use this block as a behaviour service side scripts.
- Is it an option to provide a script listener that will automatically fill in those values upon updating the issue?
no.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.