I am way out of my league here. I attempted searching the database for a script to use in scriprunner for my issue, but I have found that their answers didn't work for me. That could be because they are running scriptrunner on a server and not cloud. One solution was to use scriptrunner behaviours but I am unable to find that in the cloud version. Any help would be greatly appreciated.
Hello. You can resolve this by adding a regular expression check to the workflow transition. Much simpler than a groovy script.
Go to Project Setting > Workflows
Edit the workflow for the affected issue type
Switch to Diagram mode
On Create transition, click on the Validators
Choose Add Validator > Regular Expression Check
If you would like to restrict the field to a specific length: enter [0-9]{n}$
(n) reflects your desired field length.
You just need to set this on the required workflow transition (ideally after the initial field input is required)
What app are you using to provide the regex?
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.
While I believe you can use scriptrunner to help with this, you could also just use a bit of javascript to help here. @Andy Keyworth had a post over on https://community.atlassian.com/t5/Jira-Core-questions/Setting-a-character-limit-on-a-text-field-single-line/qaq-p/66709
with some example code, that @SABVARX also helped with.
What you can do is go into the field description in Jira, and then input a script like this:
<script type="text/javascript">
function validate()
{
if(document.getElementById("customfield_19600").value.length >33)
{
alert( "Invalid length, must be no more than 33 characters" );
return false;
}
}
document.getElementById("customfield_19600").addEventListener("keypress", validate);
</script>
In this case, you would have to substitute the 'customfield_19600' with the customfield number this is, and you can also change the specific length you want these values to be. I would recommend looking into How to find id for custom field(s)? in order to find your custom field id. And you also might need to review the documentation on Configuring a custom field in order to understand where you can edit the custom field description.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I am also lokking for the similar usecase. I have tried this script , It seems working on create screen but on edit screen this validation is not working. Any suggestions.
Appreciate your help.
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.
Hi Sudheer,
In hindsight of this answer, I think I actually prefer James Quinton's answer on this post over my own now. The approach I originally suggested to use a javascript to limit a field length is flawed. The main reason for this is that it does not cover all the ways that this field could be edited in Jira. For example, if users access the REST API to create/edit issues, they would never see this field is restricted in any way.
Whereas with James' approach, the use of a workflow validator can prevent users from entering a value you do not want to see here in both input methods. In his case, I believe he was using the JSU plugin to get this validator to work. However I'm sure there are other plugins available in Marketplace for Jira that can also provide this same kind of validator functionality. For example, the Workflow Enhancer for Jira also appears to offer regex validators, and it appears to be a free plugin at this time.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I get an error when using this script at:
<script type="text/javascript">
Is there a specific import package to be used?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Natalie,
I believe that changes to Jira Cloud have made my answer irrelevant to that platform. If you're using Jira Cloud, you can no longer add these custom java scripts to places like field descriptions or the announcement banner in Jira Cloud.
These places could still be utilized for Jira Server platforms as a way to do this. However the Cloud suite has restricted this ability.
I hope this helps.
Andy
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Andy for replying.. my bad I didn't notice this is all related to cloud. I'm actually using a server.
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.