Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Script to make Wiki-render field as restricted to deletetable from Text option as similar to visual

Maha vishnu v October 10, 2022

hello team ,

 

Find my code for requirement :

 

Assessed branch : Select list field A

Relevance : Select list field B

Commit_ID :  Wiki render field  ( with table values )

 

Based on selection of A and B - User must fill the Table value in ( Commit ID / LABEL) for specific hard coded Assessed branch table value .

Code is working perfectly . However , In wiki render field ( There is 2 option available as

VISUAL and TEXT .

 

In Visual - Deletion on table is not possible and user can able to provide / Edit values and make the movement to next transition .

In Text - Deletion of table is possible and it makes the user bypass the specific transition  . therefore , As similar to visual - deletion of tables thru TEXT option must be restricted ..

 

NEED HELP for adding the restriction script in my below script

 

Wiki render field ( Commit_ID ) must work for value provide / edit and user must not able to delete the table .

 

 

 

Working code :

 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.config.StatusManager
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.security.roles.ProjectRoleManager
// Get the fields by its name
def Assessed = getFieldByName("Assessed Branch")
def Commit_ID_field_values = getFieldByName("Commit_ID")
def Relevance = getFieldByName("Relevance")
// Get the field values
def branch = Assessed.getValue() as String[]
def relevance = Relevance.getValue() as String[]
String outcome = Commit_ID_field_values.getValue()
Commit_ID_field_values.clearError() // Clear the error message before the validation
//Get the status values
def currentStatus = underlyingIssue.getStatus().name
def validStatusList = ["Committed", "Rejected"]
if(currentStatus in validStatusList){
if (getActionName() == "Accomplish Fix" || getDestinationStepName() == "Fixed") {


def BlackArrow = ["18.1", "21.2", "Feature branch"]
def PinkArrow = ["18.1", "Feature branch"]
def BlueArrow = ["18.1", "Feature branch"]
//def YellowArrow = ["22.1", "Feature branch"]
def LilacArrow = ["21.4", "22.1", "Feature branch"]
def VividGreenArrow = ["21.2", "Feature branch"]
//def RedArrow = ["22.2","Feature branch"]
def GreyArrow = ["21.3", "22.2", "Feature branch"]
def Requiredbranchs = ["Feature branch"]

for (String rel in relevance) {
if (rel == "Scope2.1 Nissan" || rel == "Scope 2.0 ROW" || rel == "Scope2 P32R"){
if (branch != [null])
{branch.each{Requiredbranchs.add(it)?: (Requiredbranchs.contains(it))}
}
if (branch.contains("18.1")){
BlackArrow.each{(Requiredbranchs.contains(it))?: Requiredbranchs.add(it)}
}
}

else if (rel == "Scope2.1 Renault Portrait" || rel == "Scope2.1 Renault Landscape"){
if (branch != [null] && branch.contains("18.1") || !branch.contains("18.1")){ // If Assessed Branch is not empty and not containing "18.1"
branch.each{Requiredbranchs.add(it) ?: (Requiredbranchs.contains(it))} // Add Assessed Branch value to the Requiredbranchs list
}
else{
PinkArrow.each{(Requiredbranchs.contains(it))?: Requiredbranchs.add(it)} // Add BlueArrow values to the Requiredbranchs list
}
}

else if (rel == "P-IVI" ) {
if (branch != [null] && branch.contains("18.1") || !branch.contains("18.1")){
branch.each{Requiredbranchs.add(it) ?: (Requiredbranchs.contains(it))}
}
else{
BlueArrow.each{(Requiredbranchs.contains(it))?: Requiredbranchs.add(it)}
}
}

else if (rel == "Nissan ST3.x" || rel == "MMC ST3.x") {
if (branch != [null] && branch.contains("21.2") || !branch.contains("21.2")){
branch.each{Requiredbranchs.add(it) ?: (Requiredbranchs.contains(it))}
}
else{
VividGreenArrow.each{(Requiredbranchs.contains(it))?: Requiredbranchs.add(it)}
}
}

else if (rel == "Nissan AIVI2-S1" || rel == "PIVI ST3.1"){
if (branch != [null])
{branch.each{Requiredbranchs.add(it) ?: (Requiredbranchs.contains(it))}
}
if (branch.contains("21.4")){
LilacArrow.each{(Requiredbranchs.contains(it))?: Requiredbranchs.add(it)}
}
}

else if (rel == "Scope3.5 Renault Portrait" || rel == "Scope3.5 Renault Landscape"){
if (branch != [null])
{branch.each{Requiredbranchs.add(it) ?: (Requiredbranchs.contains(it))}
}
if (branch.contains("21.3")){
GreyArrow.each{(Requiredbranchs.contains(it))?: Requiredbranchs.add(it)}
}
}

else{
branch.each{Requiredbranchs.add(it)?: (Requiredbranchs.contains(it))}
}
def regex = /^.[a-zA-Z0-9!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?].*$/
if(outcome){
outcome.eachLine{
// ======================= Do the validation here
if(it != "||Assessed Branch||Commit ID/Label||"){ // Skip the table header
String firstcoloum = it.trim().split("\\|")[1] // Get the value from the first column
if(Requiredbranchs.contains(firstcoloum)){
boolean Secondcoloum = it.trim().split("\\|")[2] ==~ regex
if(!Secondcoloum){
Commit_ID_field_values.setError("You must fill the Commit ID/Label Value for " + Requiredbranchs.join(", "))
}
}
// else {Commit_ID_field_values.setError("Missing Commit ID details for the required Assessed Branch " + Requiredbranchs.join(", "))}
}
}
}
// else {Commit_ID_field_values.setError("Missing Commit ID details for the required Assessed Branch " + Requiredbranchs.join(", "))}
}
}
}

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events