Hi Team,
My requirement is date field should be added into a custom field automatically, when the XXX issue type state is moved to "xxxxxx". Using server version and also using script runner for jira plugin.
Thanks,
Hi Kammili,
There are a few ways that I believe you can accomplish this. But just to make sure I understand what you are trying to do you want to accomplish the following:
Is that correct?
If my understanding is correct and you want to use ScriptRunner, you should be able to accomplish this using a Workflow Transition Post Function and the ScriptRunner Custom script post-function. I think you can do the following:
import com.atlassian.jira.component.ComponentAccessor
// Name of the custom field to change
final customFieldName = "Test Custom Date"
// New value for that field
final newValue = new Date();
log.fatal(newValue);
def customFieldManager = ComponentAccessor.customFieldManager
def customField = customFieldManager.getCustomFieldObjects(issue).find { it.name == customFieldName }
assert customField: "Could not find custom field with name $customFieldName"
issue.setCustomFieldValue(customField, newValue.toTimestamp())
This was adopted from Custom Field Post Function script in the Adaptavist library to use a date rather than a text field.
Once you have set this up you should be able to publish your Workflow and the custom date field will be set when this post function runs upon transition.
Of course whenever making these types of changes it would be strongly recommended to test these types of changes out in a non-production workflow first. This is very simplified example I tested, so there certainly could be additional complications in your business process that need fine tuning.
But this quick example seemed to accomplish what I believe you are attempting to do in my environment.
Please let me know if this works for you or if you have any questions related to this and I would be happy to help out further.
Best,
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.