Hello Team,
There are two custom date fields Start date and Baseline start date. whenever the user select the Baseline start date and if Start date is empty then copy the Baseline start date value to start date.
here is my behavior server-side script
Welcome to the Community!
I can confirm that your approach will not work as expected.
If you intend to check to verify if the first date field has a value or passes the value of the second date field, you must create two separate Server-Side Behaviours, i.e. for each date field separately for it to work as expected.
Below are the sample working Server-Side Behaviour codes for your reference:-
1. For the Sample Date field:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import java.text.SimpleDateFormat
@BaseScript FieldBehaviours behaviours
def sampleDate = getFieldById(fieldChanged)
def baselineDate = getFieldByName('Baseline Date')
def simpleDateFormat = new SimpleDateFormat('d/MMM/yy')
if (sampleDate.value && baselineDate.value) {
return
} else if (!sampleDate.value && baselineDate.value) {
sampleDate.setFormValue(simpleDateFormat.format(baselineDate.value as Date))
}
Below is a screenshot of the Server-Side Behaviour configuration for the Sample Date field:-
2. For the Baseline Date field:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import java.text.SimpleDateFormat
@BaseScript FieldBehaviours behaviours
def sampleDate = getFieldByName('Sample Date')
def baselineDate = getFieldById(fieldChanged)
def simpleDateFormat = new SimpleDateFormat('d/MMM/yy')
if (sampleDate.value && baselineDate.value) {
return
} else if (!sampleDate.value && baselineDate.value) {
sampleDate.setFormValue(simpleDateFormat.format(baselineDate.value as Date))
}
Below is a screenshot of the Server-Side Behaviour configuration for the Baseline Date field:-
Please note that the sample codes provided above are not 100% exact to your environment. Hence, you must modify it accordingly.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Hey there,
If I understand your situation correctly, both fields are date fields. In such cases, there really is no need to overcomplicate things by formatting the value as they can just be passed along.
Grabbing the form value object and then setting it for the field in need works perfectly:
def targetStartField = getFieldById("customfield_1234")
def targetEndField = getFieldById("customfield_1235")
def targetStartObj = targetStartField.getFormValue()
def targetEndObj = targetEndField.getFormValue()
if(!targetEndObj) {
targetEndField.setFormValue(targetStartObj)
}
Let me know if you still require help with your behavior!
Best regards,
Zuri S.
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.