Facing character size limitation of 1000 to cover all combinations

Attached is the code which we wrote for Script runner validator to restrict subtask creation based on subtask field value and based on Parent Issue type. We have many conditions to restrict subtask creation so when we cover all those conditions we are facing character size limitation and also we cannot split the code in to 2 validators because if we add 2 validators then 2 validators should satisfy the condition which is not possible here since we need to act these conditions using OR. Can you help us how to optimize this code. Below is the script (whitespace added for readability):

(issue.parent.issueType.name == "Realize-Test" &&
    (issue.customfield_10850.value == "Cutover Plan" ||
        issue.customfield_10850.value == "Go-Live Readiness Assessment" ||
        issue.customfield_10850.value == "Go Live Business Contingency Plan/FMEA")) ||
(issue.parent.issueType.name == "Realize-Build" &&
    issue.customfield_10850.value == "Deployment Strategy and Approach") ||
(issue.parent.issueType.name == "Mobilize" &&
    (issue.customfield_10850.value == "Enterprise Structure Decisions" ||
        issue.customfield_10850.value == "Business Process Design" ||
        issue.customfield_10850.value == "Technical Infrastructure Scope" ||
        issue.customfield_10850.value == "Change Management Strategy" ||
        issue.customfield_10850.value == "Change Impact Assessment")) ||
(issue.parent.issueType.name == "Initiate" &&
    (issue.customfield_10850.value == "Statement of Requirements" ||
        issue.customfield_10850.value == "Business Case Documentation" ||
        issue.customfield_10850.value == "Project Workplan" ||
        issue.customfield_10850.value == "Project Cost Analysis")) ||
(issue.parent.issueType.name == "Blueprint" &&
    (issue.customfield_10850.value == "Application Landscape" ||
        issue.customfield_10850.value == "Security, Privacy, and Controls Governance Approach" ||
        issue.customfield_10850.value == "Data Migration/Conversion Strategy" ||
        issue.customfield_10850.value == "Environment Management Approach" ||
        issue.customfield_10850.value == "Reporting Approach" ||
        issue.customfield_10850.value == "Integration Strategy"))
1 Like

Looking at the repeating checks I think you could create a map and then loop through its entries. Something like:

    'Realize-Test': ['Cutover Plan', 'Go-Live REadiness Assessment', 'Go Live Business Contingency Plan/FMEA'],
    //add more
.some(entry => issue.parent.issueType.name == entry[0] && entry[1].includes(issue.customfield_10850.value))

I think there is a number of ways you can structurize it. Take a look the the Jira Expression list docs for example.

1 Like