We're on JIRA cloud and are trying out the ScriptRunner addon. Is it possible to set a custom date picker field with the current date/time in a workflow transition's post function? If so, how would I do so?
By playing around with a test workflow, I think I found what you need:
I have not tested this, but I'm trusting what I read on screen on Step 6 as JIRA shows:
Please make sure that the value you enter is valid for custom field its datatype
and context configuration for the project using this workflow.
Otherwise, the transition may fail at execution time.
Additionally to enter text or numbers as value, you may use the following:
- You may use macro '%%CURRENT_USER%%' to insert the function caller.
- You may use macro '%%CURRENT_DATETIME%%' to insert the current date and time.
- You may use macro '%%ADD_CURRENT_USER%%' to append the function caller. Obsolete please use append option instead with user macro above.
- For Cascading Select fields, you may either use the value of the option to be selected, no need to add the parent for childs. Or simply enter the ID of the option to be selected.
Here is code for custom script post-function:
import com.atlassian.jira.component.ComponentAccessor import com.atlassian.jira.event.type.EventDispatchOption import com.atlassian.jira.issue.MutableIssue import com.atlassian.jira.issue.UpdateIssueRequest import java.sql.Timestamp issue.setCustomFieldValue( ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("customFieldname") , new Timestamp() ) //only for create transition /* ComponentAccessor.getIssueManager().updateIssue( ComponentAccessor.getJiraAuthenticationContext().getUser() , issue , UpdateIssueRequest.builder().sendMail(false).eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).build() ) */
Edit your workflow, add new post-function on the action of type "Script Post-function".
Choose "Modify Issue" function.
Enter the following code:
issueInput.fields.customfield_10132 = new Date().format("yyyy-MM-dd")
where 10132 is the ID of the custom field you want to update.
I'm getting this error now. Is there any way to set this field without having to surface it on my screens? I'd rather not allow users to change this value.
2016-11-21 19:09:28,388 INFO - Serializing object into 'interface java.util.Map' 2016-11-21 19:09:28,390 INFO - PUT /rest/api/2/issue/80258 asObject Request Duration: 326ms 2016-11-21 19:09:28,403 ERROR - assert resp.status == 204 | | | | 400 false status: 400 -` Bad Request body: [errorMessages:, errors:[customfield_15500:Field 'customfield_15500' cannot be set. It is not on the appropriate screen, or unknown.]]
Connect with like-minded Atlassian users at free events near you!Find a group
Connect with like-minded Atlassian users at free events near you!
Unfortunately there are no AUG chapters near you at the moment.Start an AUG
We're bringing product updates and pro tips on teamwork to ten cities around the world.Save your spot