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.
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
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fabio Racobaldo _Herzum_ ,
I used the same code but iam getting below error please find the screenshot
Regards,
Geethanjali.
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.
wht's your jira and script runner version?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fabio Racobaldo _Herzum_ ,
we are using jira server version 8.5.1
And script runner version 6.15.0
Regards,
Geethanjali.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fabio Racobaldo _Herzum_ ,
The code works thanks a lot for your valuable time and information.
Regards,
Geethanjali.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Fabio Racobaldo _Herzum_ , perfect solution I was also looking for. Thank you very much for the code!!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you are welcome @Karl Samson
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.