Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Script in Behaviour Field in Jira

Sharadkumar Bangera
Contributor
September 4, 2019

Hi,

I am trying to add the Value "Testing1" in Organization Field automatically when the status get changed.

For eg if the Status changed to "Waiting Internal" then Organisation field should automatically  updated "Testing1"

Below is my script but its not working

*******************

def Organizations = getFieldByName("getFieldByName")

def status = getFieldById("getFieldById")

def customer = getFieldById("customfield_12345")

                         

if (status.getValue() == "Waiting Internal")

if (customer.getValue() == "ABCD"){

    Organizations.setFormValue("Testing1")

         }

 

1 answer

0 votes
Leo
Community Champion
September 4, 2019

Hi @Sharadkumar Bangera,

If field update needs to happen only after particular transition, you can try out ScriptRunner Post-function

Post-Function --> Script Post-Function[ScriptRunner] --> Custom script

please find code snippet for custom field update in workflow transition

import com.atlassian.jira.component.ComponentAccessor

def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Custom Field Name")
def value = "value to update in field"

issue.setCustomFieldValue(cfUpdate, value)

 BR,

Leo

Sharadkumar Bangera
Contributor
September 4, 2019

Thanks Leo, I will try it tomorrow and update you.

I also wanted to know if i have 2 requirement and if it meet then only the field to be added automatically.

For eg if the Status changed to "Waiting Internal" and Customer = "ABCDEF" then Organisation field should automatically  updated "Testing1" else if 

Status changed to "Waiting Internal" and Customer = "XYZ" then Organisation field should automatically  updated "Testing2"

Leo
Community Champion
September 4, 2019

Hey, It's quite simple

If you add post function in "Waiting Internal" transition, your 1st condition will be always true when this script executes 

And for 2nd you just need to add if..else. below snippet may help you :)

import com.atlassian.jira.component.ComponentAccessor

def cfUpdate = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Organization")
def cfCustomer = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer")
def customer = issue.getCustomFieldValue(cfCustomer)

if(customer == "ABCDEF"){
issue.setCustomFieldValue(cfUpdate, "Value to update here")
}else{
issue.setCustomFieldValue(cfUpdate, "Value to update here")
}
Sharadkumar Bangera
Contributor
September 4, 2019

Thanks Leo.

I will try this tomorrow..Have a good day

Sharadkumar Bangera
Contributor
September 5, 2019

Hi Leo,

I tried this script but nothing is happening.

when i update customer "ABCDEF" the Organisation field remains blank

Leo
Community Champion
September 5, 2019

Hi @Sharadkumar Bangera,

There are 2 things, 

1. Script I provided for post-function, which will work only during issue transition. if you want it to work during issue update then we can give a try with custom listener with issue update event

2. Also this script is to update normal text field, is your Organization field text field or Select list?

 

BR,

Leo 

Sharadkumar Bangera
Contributor
September 5, 2019

Hi Leo,

 

Organisations is a custom field not a list.

I can add only Group name here For eg the group name is "Testing1" and Testing 1 added with several users under customer page

Group Name is Testing1 and it contain several users

1) ambc@XXXX.com 

2) dffc@XXXX.com 

1) amffffbc@XXXX.com 

Leo
Community Champion
September 5, 2019

Hey, 

I haven't done any script with group picker field, you can refer this post for group field update: https://community.atlassian.com/t5/Jira-Service-Desk-questions/Need-Help-to-Update-Group-Picker-Field-By-using-the-Script-post/qaq-p/1023947

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events