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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Limiting Behaviour Script to Create Issue Action

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 Community Leader Jan 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
}

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 Community Leader Feb 03, 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.

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you