Limiting Behaviour Script to Create Issue Action

Mike Madore January 30, 2020

I created an Initialiser script to put a table in a field as the default value. The 2nd column that is blank when created will then be updated as work progresses. The Behaviour works as an Initialiser or Server side if it is not limited to the Create Issue action.

If I put a condition at the start of the Behaviour it does not enter the default value.

if (getAction()?.id != 1) {

    return // not the initial action, so don't set default values

}

 

I also tried setting the condition “When: Workflow Action: Create Issue (1) but this had no impact.

 

How can I insert the default table information without having it overlay the updates the next time the issue is edited?

 

Script runner - 5.6.14.1-p5

Jira 8.5.0

 

1 answer

1 vote
Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 30, 2020

Here is how I accomplish that in a Behaviour, including the comments from my script explaining what's going on:

// We wish to run this behaviour only during a Create.
// Per https://scriptrunner.adaptavist.com/5.4.28/jira/behaviours-api-quickref.html#_getactionname :
// getActionName() "Returns the name of the current action if the issue is undergoing a workflow action, null otherwise."
// Create is a workflow action, so it will return "Create Issue" or "Create" (should check for both).
// Edit is not a workflow action, so it will return null.
if (getActionName() == null || !(getActionName() in ["Create Issue", "Create"])) {
return
}
Mike Madore February 3, 2020

I copied the condition you sent into my script and the create does not fill in the Default Values. If I remove the condition it will put the Default table into the field every time it is edited. 

Here is a copy of my script.

if (getActionName() == null || !(getActionName() in ["Create Issue", "Create"])) {
return
}

def desc = getFieldById("customfield_19506") // Field name = Adobe Categorization, Large Text field
def defaultValue = """|| Campaign Categorization || Every line must have a selection||
| Line of Business:
* Mobile, Home | |
| Segment:
* Consumer, Business, Reporting | |
| Audience: (Selection)
* Base, Prospect, Other | |
| Program Type: (Selection)
* Behavior/Trigger, Ad Hoc/ Event/ Overlay, Cadence, Unspecified | |
| Primary Objective: (Selection)
* AAL, Legacy, Loyalty/Churn, Newsletter, Notifications, Onboarding, Pricing, RevGen, Reqwards Self-Serve, Test, Upgrade/Renewal | |
| Secondary Objective: If applicable (Selection)
* NA, Accessories, Music, Call Filter, Cloud, Digital Secure, Plus, Int Long Distance, Project, Family, TMP, Travel Pass | |
| Additional Tagging: If applicable (Selection)
* Coverage, AAL, Legacy, Loyalty/Churn, Newsletter, Notifications, Onboarding, Paperless, Plan Migration, Pricing, Redemption, Reporting, RevGen, Self-serve, Surveys, Test, Upgrade/Renewal | |""".replaceAll(/ /, '')

desc.setFormValue(defaultValue)

Payne
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 3, 2020

I would log the value you're getting for getActionName()

On the Behaviours listing page, click enable logging, and then at the top of your Behaviour add the following line:

log.debug("getActionName() : "+getActionName())

Then create an issue and check atlassian-jira.log to see its value.

Santosh Subramani April 7, 2021

where can i find click enable logging, i dont see it in Behaviors page

Could you  please let me know where could i find logging option 

Suggest an answer

Log in or Sign up to answer