Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Table of Contents

...

Button handy
blanktrue
color#0052CC
nameSend Feedback
linkhttps://docs.google.com/forms/d/e/1FAIpQLScmToBe3vynAlb5fdKwCGxYqnTbDc66sIBgeecG2BuFDuHc7g/viewform?entry.2002826954=Limit+the+number+of+characters+in+a+text-entry+field+-+15480219
widthauto

Table of Contents

Problem

  • You want to limit the number of characters a user enters into a single-line or multi-line text field.

  • You want to indicate how many characters remain and if the maximum is exceeded.

Let's see how you can achieve the above scenarios using Power Scripts™ for Jira, a powerful scripting tool to help automate your Jira.

What these Scripts do

  • The listener script listens to the Summary field and runs the executor script on any character entry or removal.

  • The executor script checks the number of characters against a declared maximum and disables the create/submit button if exceeded.

Image ModifiedImage Modified

Configure Live Field Listener

You should configure this script as a Live Field script for the relevant project. This Live Field script listens to the Summary field and provides feedback for how many characters the user has entered by invoking lfExecutor_CharacterLimitSummary.sil.

Code Block
if(argv["screen"] == "create" || argv["screen"] == "edit") {
  lfWatch("summary", {"summary"}, "lfExecutor_CharacterLimitSummary.sil" , {"keyup"});
}

Listener References Live Field Executor

lfExecutor_CharacterLimitSummary.sil

This Live Field script checks how many characters have been entered in the Summary field and gives feedback. It also removes the ability to create or edit the issue if the number of characters exceeds an arbitrary value (we'll use 140 characters as an example).

Code Block
number sumLength = length(argv["summary"]);
number maxLength = 140;
number remLength = maxLength - sumLength;

string showRem = remLength;

if (sumLength<=maxLength) {
    lfShowFieldMessage("summary", showRem+" characters remaining", "INFO");
    lfEnable("editSubmit");
    lfEnable("transitionSubmit");
    lfEnable("createIssueSubmit");
    lfEnable("issueCreateSubmit");
}
else {
    lfShowFieldMessage("summary", "Character count exceeded!", "ERROR");
    lfDisable("editSubmit");
    lfDisable("transitionSubmit");
    lfDisable("createIssueSubmit");
    lfDisable("issueCreateSubmit");
}