Hi Team,
I used Scriptrunner behavior for this requirement.
If we select "Artifacts Ready" = "Yes" when creating a ticket, the system will automatically populate the "Artifacts Added Date" field with the current date.
def ArtifactDate = getFieldByName("Artifacts Added Date")
def Artifacts = getFieldById(getFieldChanged())
if (Artifacts.getValue() == "Yes") {
ArtifactDate.setFormValue(Calendar.getInstance().format("d/MMM/yy"))
} else {
ArtifactDate.setFormValue(null)
}
Hi @Lakshmi CH
After reading your description, it sounds like your Behaviour has been configured on the Initialiser instead of the Server-Side Script.
I am saying this because if a Server-Side Behaviour has been configured for a particular field, that Behaviour will not take effect unless a modification or a value is set to the field. However, in your case, the Behaviour seems to happen when clicking the Edit button.
To proceed, could you please clarify if this is the case?
Also, it would be beneficial if you could share a screenshot of your Behaviour configuration.
Thank you and Kind regards,
Ram
Hi @Ram Kumar Aravindakshan _Adaptavist_ , Thank you for the quick responses.
I have included a server-side script, however, whenever the user attempts to modify other fields on the edit screen, the "Artifacts Added Date" is automatically updated to the most recent date.
Please find attached screenshots for your reference.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lakshmi CH
I am going to assume that the Artifacts Added Date field is a Single Select List.
I have tested the code in my environment, but I'm not facing any issues.
Below is the working sample code that I have tested with:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def sampleList = getFieldById(fieldChanged)
def sampleListValue = sampleList.value.toString()
def date1 = getFieldByName('Date 1')
if (sampleListValue == 'Option 1') {
date1.setFormValue(Calendar.instance.format('dd/MMM/yy'))
} else {
date1.formValue = ''
}
Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.
Below is a screenshot of my Server-Side Behaviour configuration:-
I have run a test on my environment, i.e. the Edit screen and it seems to work as expected.
Below is a test screenshot for your reference:-
In my environment, I am testing with a Single Select List called Sample List, and it has options Option 1, Option 2, Option 3 and Option 4. So in the create screen if Option 1 is selected the Date 1 field will be updated to the current date.
Also if I try to edit the issue, the value for the Date 1 field is not changed. Only if I change the option from the Select List does the Date 1 field get updated.
I would suggest to upgrade your ScriptRunner plugin to the latest release, i.e. 8.6.0 and try to rerun the test.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Ram Kumar Aravindakshan _Adaptavist_ ,
"Artifacts Ready" is a check box with the single option "Yes," and "Artifacts Added Date" is a date field. I updated the addon version to 8.6.0. I tried on the dev instance, but it's still updating to the current date when I updated other fields.
If you check the attached screenshot, the "Artifacts Added Date" is 07/07/2023, but when I opened the edit, "Artifacts Added Date" is 11/July/2023. I didn't update anything; I just clicked on edit, the date showing the current date. Is there any mistake in my script?
I think, When opening the edit, there is a pre-checked box with a single value of "Yes." Additionally, the date field is being considered for an update.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Lakshmi CH
I have re-run the test once again, this time using the check box instead of the list, and I am still not encountering any issues.
Below is the working sample code that I have tested with:-
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours behaviours
def sampleCheckBox = getFieldById(fieldChanged)
def sampleCheckBoxValue = sampleCheckBox.value.toString()
def date1 = getFieldByName('Date 1')
if (sampleCheckBoxValue == 'Yes' && !date1.formValue) {
date1.setFormValue(Calendar.instance.format('dd/MMM/yy'))
}
Please note that the working sample code above is not 100% exact to your environment. Hence, you will need to make the modifications.
Below is a screenshot of the Server-Side Behaviour configuration.
I suspect the root cause of your problem is the approach you used to set the if/else condition. In your if condition below, you have only checked if the Artifacts field has a value, but you have not checked if the date field has a value or not, as I have done in my example above. This is what is causing the date field to keep updating.
if (Artifacts.getValue() == "Yes") {
ArtifactDate.setFormValue(Calendar.getInstance().format("d/MMM/yy"))
} else {
ArtifactDate.setFormValue(null)
}
I am also including a couple of test screenshots for your reference:-
1) I created the issue on 11 July, and the date was set as expected.
2) Below is the view screen where the date field is set to 11 July.
3) Today, on 13 June, I tried to edit the issue, but the date has not been updated as shown in the screenshot below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank you so much Ram @Ram Kumar Aravindakshan _Adaptavist_ . I have implemented the changes you recommended in the code, and it is now functioning as expected. Additionally, I have observed that the date remains constant even after opening the edit.
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.