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

VIP User - ScriptRunner Scripted Field on Create Issue Screen

I have been researching different ways to show certain users as VIPs and it doesn't look promising. We would specifically like to see this on the Create Issue Screen as well as the other issue screens. This would help our agents know if they are talking to a VIP as soon as they take the call and input their name.

I am wondering if you can use a ScriptRunner Scripted Field to automatically pull the reporter that you enter and check if they in a few certain groups and display the result right on the Create Issue Screen.

I do not have a lot of experience with writing code but I can follow along.

It also doesn't necessarily have to be ScriptRunner either. Anything that can accomplish what we are looking for would be great!

We are running Jira 8.2.3 and Jira SD 4.2.3 and Scriptrunner is close the latest and can be easily updated.

Thanks!

1 answer

1 accepted

1 vote
Answer accepted

Hi,

 

Do you already have the users mapped out somehow? Probably in a group?

If so, you could use Script Runner Behaviours.

It's an easy method of assessing Jira forms and making decisions/changes based on the field values.

I'm thinking something of a Read only field, or maybe even a checkbox.

 

As soon as the form Loads, the behavior should check the reporter, if that reporter is part of the "VIP" group, then it should either write the Read only field or maybe check a box "VIP Customer"

I don't currently have them mapped out but yes I was thinking of using groups such as VIP, Internal, External, etc.

When you say, "As soon as the form loads", are you saying as soon as the reporter field is filled out or when the issue is created? I'm looking to for it to reflect the information immediately on the create issue screen while they are still talking to the user and filling out ticket details.

This sounds promising though. We already have a behaviour setup to only allow certain priorities depending if the user is in a certain group. I just wasn;t sure how we would use that to display something new on the screen.

Again, not much of a coder so I could use some help on that.

Now I understand that the agent, while on the phone call creates the issue for the user.

In that case I would add a checkbox field named "Type".

Example values = "Internal", "External", "VIP".

Add a behavior for the specific project/issue type

Add a server script for field Reporter

 

The basic script would look something like this (tested)

import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def group1 = groupManager.getUserNamesInGroup('jira-administrators')

def reporter = getFieldById("reporter").getValue()

if(group1.contains(reporter)){
getFieldByName("Type").formValue = 10202 //checkbox option of VIP
}else{
getFieldByName("Type").formValue = ""
}

 

Of course you would need to enhance this script based on your field name and also some if/else or switch cases based on multiple user groups.

 

Hope this helps

@Gezim Shehu -Communardo- 

Okay so I think I'm close but I cannot get this to work. I made the script a server side script for the reporter field but do I need an initialiser also?

Scriptrunner does not give any errors for the script.

It does not update the field on either the create or view/edit screens.

import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def ITManagers = groupManager.getUserNamesInGroup('Jira-Managers-IT')
def VIP = groupManager.getUserNamesInGroup('Jira-VIP')
def ITDev = groupManager.getUserNamesInGroup('Jira-Dept-Dev')
def ITSP = groupManager.getUserNamesInGroup('Jira-Dept-SP')

def reporter = getFieldById("reporter").getValue()

if(ITManagers.contains(reporter)){
getFieldByName("User Priority").formValue = "IT Manager" //checkbox option of VIP
}else if(VIP.contains(reporter)){
getFieldByName("User Priority").formValue = "VIP"
}else if(ITDev.contains(reporter)){
getFieldByName("User Priority").formValue = "IT"
}else if(ITSP.contains(reporter)){
getFieldByName("User Priority").formValue = "IT"
}else{
getFieldByName("User Priority").formValue = ""
}

I think your problem lies in the values. If you use formValue you need to specify the select option ID. You can find this in the URL when you try to edit the value of an option.

Take a look at the value I used.

 

In case you want to use the text values I believe you need to query over the possible options of the custom field, for that context.

Like Travis Chafey likes this

I also tried using:

getFieldByName("User Priority").setFormValue("IT Manager")

I definitely need it to fill out a Text box because if I do checkboxes it will fill up too much of the page. I'm not sure where to go form here though.

@Gezim Shehu -Communardo- 

Would it be feasible to do it with a "Select List (single choice)" field and make it read-only?

@Gezim Shehu -Communardo- 

Okay, so I remade the custom field as a "Select List (single choice)" with a few options. Added them to the create and view/edit screens for a Service Desk project. Created a new Behaviour with no Validator plugin, no guide workflow, and no initialiser. Added a server-side script for the Reporter field. Edited each custom field option to get the option value id at the end. Mapped it to all issue types for the project.

Here is the script (it gave no errors):

import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def ITManagers = groupManager.getUserNamesInGroup('Jira-Managers-IT')
def Fed = groupManager.getUserNamesInGroup('Jira-Oversight')
def VIP = groupManager.getUserNamesInGroup('Jira-VIP')
def ITDev = groupManager.getUserNamesInGroup('Jira-Dept-Dev')
def ITSP = groupManager.getUserNamesInGroup('Jira-Dept-SP')

def reporter = getFieldById("reporter").getValue()

if(ITManagers.contains(reporter)){
getFieldByName("User Priority").formValue = 10502
}else if(Fed.contains(reporter)){
getFieldByName("User Priority").formValue = 10504
}else if(VIP.contains(reporter)){
getFieldByName("User Priority").formValue = 10503
}else if(ITDev.contains(reporter)){
getFieldByName("User Priority").formValue = 10505
}else if(ITSP.contains(reporter)){
getFieldByName("User Priority").formValue = 10505
}else{
getFieldByName("User Priority").formValue = ""
}

 It does not update the field before or after creating the ticket.

Then, I created a custom field called Type as a Checkbox field with the only option as VIP. Used the script from above and changed only the group and value.

It did not work. Is there something I'm missing on my end?

I have created a custom field "User Priority" of type "Checkboxes".

I have configured a Behavior and added a Server Side Script on the "Reporter" Field.

This script executes correctly for me on the Create Issue Screen.


Can you check again? (Type of Custom Field and if correct Group Names)

import com.atlassian.jira.component.ComponentAccessor
def groupManager = ComponentAccessor.getGroupManager()
def group1 = groupManager.getUserNamesInGroup('jira-administrators')
def group2 = groupManager.getUserNamesInGroup('jira-software-users')

def reporter = getFieldById("reporter").getValue()

if(group1.contains(reporter)){
getFieldByName("User Priority").formValue = 10200
}else if(group2.contains(reporter)){
getFieldByName("User Priority").formValue = 10201
}else{
getFieldByName("User Priority").formValue = ""
}

 

Like Travis Chafey likes this

Doesn't seem to be working for me.

Created the Checkbox Custom Field named User Priority and attached it to the proper screens:

UserPriority.png

UserPriority2.png

Grabbed the values from the options:

UserPriority3.png

 

Created the Behaviour:Behaviour.png

 

Tested with users in the software and admin groups:

SoftwareUser.pngAdminUser.png

And nothing happens. Even if I create the ticket, it doesn't check the box on the view screen.

Try and change the mapping type from Service Desk, to project/issuetype

Like Travis Chafey likes this

@Gezim Shehu -Communardo- 

Success! Thank you!

Is there a way I can make this read only so that they cannot change it?

Thanks!

Sure, you could either add a mapping for the custom field, or simply append this line after setting the custom field value



getFieldByName("User Priority").setReadOnly(true)
Like Travis Chafey likes this

While that does work, it makes the field yellow. Is there a way around that?

Forgot to put in the boolean argument.

What do you mean yellow? Does not happen to me

I think this is normal greyed out. Maybe you want to set it hidden then?

Like Travis Chafey likes this

Thanks for all your help Gezim.

Sure anytime,

 

Cheers

Suggest an answer

Log in or Sign up to answer
Community showcase
Posted in Jira

Demo Den Ep. 7: New Jira Cloud Reports

Learn how to use two new reports for next-gen projects in Jira Cloud:  Cumulative flow diagram and Sprint burndown chart. Ivan Teong, Product Manager, Jira Software, demos the Cumulative ...

231 views 1 2
Join discussion

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