Bhavya-org / Scripts

1 stars 0 forks source link

test #66

Open sani-d opened 3 months ago

sani-d commented 3 months ago

// This Script Listiner should be configured to run on the Issue Link Created Event

// Check if the type of the issue link type of the issue is 'Cloners' which is the issue link type that Jira uses when cloning an issue. // If it is a cloned issue then perform the logic to clear field values if (issueLink.issueLinkType.name == "Cloners"){ logger.info("The issue has been cloned so now removing the values from the fields which should not be set") // Below we make a put request to the Issue API to update the issue and to set the fields we want to set to null

// get custom fields
def customFields = get("/rest/api/2/field")
    .asObject(List)
    .body
    .findAll { (it as Map).custom } as List<Map>

// Specify the custom field name below for the Single Line Text Field ensuring the < and > characters are removed.
def singleLineTextField = customFields.find { it.name == 'Story Points' }?.id
//def numberField = customFields.find { it.name == 'Fix versions' }?.id

// Note in this example we just set the description to null and you will need to specify any extra fields which you wish to have no value in the 'fields' section of the body for the rest call below.
def clearValues = put("/rest/api/2/issue/${issueLink.sourceIssueId}")
//.queryString("overrideScreenSecurity", Boolean.TRUE)
        .header('Content-Type', 'application/json')
        .body([
        fields: [
                fixVersions: null,
                (singleLineTextField):null, // set the description to have no value
                //(numberField):null, // set the description to have no value
                customfield_11181:null, // set the single line text field custom field to have no value
                customfield_11182:null // set the single line text field custom field to have no value
        ]
])
        .asString()

// If the issue is not a clone then log a message saying this and do nothing }else{ logger.info("The issue has not been cloned so do nothing") }