Hello Atlassian Community
I want to create an issue via Jira Automation, which has a ScriptRunner Issue Picker field set as a required field. I do have a statis value but it cannot simply be set via Choose a field to set since this custom field type is probably not supported.
Hence, I need to use More options and tried:
{
"fields": {
"customfield_XXXXX": "JIRA-7"
}
}
But its's unsuccessful: We can't create this issue for you right now, it could be due to unsupported content you've entered into one or more of the issue fields. If this situation persists, contact your administrator as they'll be able to access more specific information in the log file.
I tried variations like
{
"fields": {
"customfield_XXXXX": {"key": "JIRA-7"}
}
}
or providing the URL but nothing worked.
Could someone please point me in the right direction?
Cheers
Nadine
For your requirement, I suggest using ScriptRunner's HAPI feature to simplify your code. Please ensure that you have upgraded your ScriptRunner plugin to the latest release, i.e. 8.18.0.
Below is a sample working code for your reference:-
issue.update {
setCustomFieldValue('Sample Picker', 'ST-1')
}
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 the Automation configuration:-
Below are a couple of test screenshots for your reference:-
1. When the issue is being created only the Summary and Description fields are filled. The Issue Picker field is left empty as shown in the screenshot below:-
2. Once the issue is created, you will notice that the Issue Picker field is automatically updated to the value that has been set in the Automation configuration as shown in the screenshot below:-
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Hello @Ram Kumar Aravindakshan _Adaptavist_
Thanks a lot for your input. We are riding on a dino Jira at the moment but I shall try that approach after our planned upgrade and let you know.
The only thing I am wondering about is how it works when this issue picker field is required and needs to be set in the create-transition....
I'll need to think about it and maybe change the entire way this is set up.
Anyways, I'll test and accept your answer if it works.
Best regards
Nadine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
If you intend to set a field to mandatory, you won't be able to do this via Automation.
Instead, you will need to use ScriptRunner's Behaviour.
In your case, since you want to set it to mandatory without having any dependency on a field value (I am assuming this is the case), you can use Behaviour Initialiser for this.
Below is a sample working Behaviour Initialiser code for your reference:-
def samplePicker = getFieldByName('Sample Picker')
samplePicker.required = true
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.
Hello @Ram Kumar Aravindakshan _Adaptavist_
Thanks again for responding so quickly.
My problem is not that I need to set the field required but that it is required and needs to be set during creation.
With your first approach the script only runs when the issue has already been created and since it is a separate automation entry, I was wondering how to make it work when the trigger is scheduled and the first action is Create Issue.
Maybe behaviour is a solution anyway if I make the field optional for my automation user and run your script as second action.
I“ll check that!
Best regards
Nadine
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In your last comment, you mentioned:-
My problem is not that I need to set the field required but that it is required and needs to be set during creation.
This is the same as setting the field to required, i.e. it must be filled during the creation process, else it will fail.
You also mentioned:-
With your first approach the script only runs when the issue has already been created and since it is a separate automation entry, I was wondering how to make it work when the trigger is scheduled and the first action is Create Issue.
As I mentioned earlier, you can't use Automation or even a Scheduled task to set a field to required. This can only be done via Behaviour.
However, you could use a Validation on the Create transition, whereby if the field is empty, the creation process will not occur. Please refer to this ScriptRunner Documentation as well as this ScriptRunner Documentation for more information.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.