Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

When Date picker field modified make comment required

Geethanjali S J
Contributor
November 11, 2021

Hi All,

We are using server and our requirement is when we change date picker field the comment field should be required.

Can anyone help with this.

Regards,

Geethanjali.

2 answers

2 accepted

2 votes
Answer accepted
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 11, 2021

Hi @Geethanjali S J ,

in order to make a field required based on other field value or change, you should use a behaviour ( https://scriptrunner.adaptavist.com/latest/jira/behaviours-overview.html ) provided by Script Runner Plugin (https://marketplace.atlassian.com/apps/6820/scriptrunner-for-jira?tab=overview&hosting=server).

Hope this helps,

Fabio

Geethanjali S J
Contributor
November 11, 2021

Hi Fabio,

Thanks for the reply l know that we can do this by behaviours can you please send me the script if you have any.

Any example script regarding my requirement.

Regards,

Geethanjali.

1 vote
Answer accepted
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 11, 2021

Hi @Geethanjali S J ,

here requested code :

import java.text.SimpleDateFormat
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.component.ComponentAccessor
import java.sql.Timestamp
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.fields.CustomField

Issue issue = getUnderlyingIssue();

def dateField = getFieldByName("HERE_YOUR_DATE_PICKER_FIELD_NAME");
def commentField = getFieldById("comment");

if(issue!=null){
CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField dateCustomField = customFieldManager.getCustomFieldObjectByName("HERE_YOUR_DATE_PICKER_FIELD_NAME");
Timestamp dateCustomFieldTimestamp = issue.getCustomFieldValue(dateCustomField)!=null?(Timestamp)issue.getCustomFieldValue(dateCustomField):null;
String dateCustomFieldValue = issue.getCustomFieldValue(dateCustomField)!=null? new SimpleDateFormat("MM/dd/yy").format(new Date(dateCustomFieldTimestamp.getTime())):"";
String dateValue = dateField.value!=null?(dateField.value as Date).dateString:"";
if(!dateValue.equalsIgnoreCase(dateCustomFieldValue)){
commentField.setRequired(true);
} else {
commentField.setRequired(false);
}
}

Ciao,

Fabio

Geethanjali S J
Contributor
November 11, 2021

Hi @Fabio Racobaldo _Herzum_ ,

I used the same code but iam getting below error please find the screenshot


IMG-20211111-WA0000.jpg

Regards,

Geethanjali.

Geethanjali S J
Contributor
November 11, 2021

IMG-20211112-WA0000.jpg

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 11, 2021

Hi @Geethanjali S J 

wht's your jira and script runner version?

Geethanjali S J
Contributor
November 12, 2021

Hi @Fabio Racobaldo _Herzum_ ,

we are using jira server version 8.5.1

And script runner version 6.15.0

Regards,

Geethanjali.

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 12, 2021

Hi @Geethanjali S J ,

you should add this code in a behaviour and not in console script.

So, create a behaviour, add a mapping to the desired projects/issueTypes and put my code in the intializer (server side script)

Fabio

Geethanjali S J
Contributor
November 12, 2021

Hi @Fabio Racobaldo _Herzum_ ,

The code works thanks a lot for your valuable time and information.

Regards,

Geethanjali.

Karl Samson
Contributor
June 10, 2022

Hi @Fabio Racobaldo _Herzum_ , perfect solution I was also looking for. Thank you very much for the code!!

Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
June 10, 2022

you are welcome @Karl Samson 

Suggest an answer

Log in or Sign up to answer