Forums

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

Is it possible to hide a page/section from a user in Jira Service Desk with ScriptRunner

Silas Alexander Lykke Rosenskjold
January 11, 2021

Hi everyone,

 

I have two quick about hiding elements/pages from a user in Jira Service Desk.

 

Is it possible to hide a certain page inside a project from a specific user with ScriptRunner?

I would like to hide the page /customers in a service desk for a specific service desk agent.

 

I know there's a built-in script that can hide the menu icon for customers.

Is it possible to do on a user-level, so that only a particular user in a project doesn't see that menu icon?

 

Thanks a lot in advance :)

Jira server: 8.13.1

Jira service desk: 4.13.1

1 answer

Suggest an answer

Log in or Sign up to answer
0 votes
PD Sheehan
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 Champions.
July 27, 2020

You say "listener" script, but I see "getFieldById" which is a behavior method.

If you are truly intending to use a listener, then yeah, that script will never work.

So I'll assume from here on out that this is a behaviour server-side script on the "component/s" field. 

The first issue with your script is that you are getting a list of project Components, but then comparing a single item to the list using ==. That won't work.

If you want to know if "product" was a selected component, you can try this

def components = getFieldById(getFieldChanged()).getValue() as List<ProjectComponent>
if(components.any{it.name == 'Product'){
//set the assignee here
}

The second issue is in trying to set that assignee custom field.

Since we're assuming behaviour script, that means you want the assignee to be applied immediately when the components are changed, this will need to be done by getting a behaviour formfield object (similar to how you got the component). Then using the setFormValue method to select the value

def customerAssigneeFormField = getFieldById('customField_10401')
customerAssigneeFormField.setFormField(user2)
Shah Baloch
Contributor
July 27, 2020

@PD Sheehan Yeah I kind of mixed up, because trying both and make it work. I tried your script but getting errors. Do I need to add any  other lines or code? I appreciate your help.

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def components = getFieldById(getFieldChanged()).getValue() as List<ProjectComponent>
if(components.any(it.name == 'Product')){
def user2 = 'dthompson'



def customerAssigneeFormField = getFieldById('customField_10401')
customerAssigneeFormField.setFormField(user2)
}

 

Thanks

gv_01.pnggv_02.png

 

PD Sheehan
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 Champions.
July 27, 2020

What sort of errors are you getting specifically?

I see I was a little sloppy in my previous response (missing closing bracket and wrong method name)

This should work, provided that "Product" is the actual name of the component and that cvigil is an actual user name. Also, I've made the assumption that dthompson is the default assignee when it is not 'Product'. 

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def custAssignee = 'dthompson'
def components = getFieldById(getFieldChanged()).value as List<ProjectComponent>
if(components.any{it.name == 'Product'}){ //any requires curly brace
custAssignee = 'cvigil' //don't forget closing quote
}
def customerAssigneeFormField = getFieldById('customField_10401')
customerAssigneeFormField.setFormValue(custAssignee)

Like Shah Baloch likes this
Shah Baloch
Contributor
July 28, 2020

For some reason it is not assigning the value to the field. I copied and pasted the script, which didn't need any change except custom field id (customFieldId_10401), but it is not working. I can manually add user in the field which you can see in the screen shot.

Which field should I map? Component or custom Assignee field? I tried both added one field it didn't work,  deleted and tried the other one, same issue, not adding value in the custom assignee field.

When I click on "Assignee" custom field for configuration it shows me the value "customFieldId=10401", if I use equal sign instead of underscore, it won't let me to create a ticket "Leave Site" popup comes up on the screen.

I tried all the name of CF field, like 10401, cf[10401], customFieldId=10402, customFieldId_10401. It is not assign user to the field. I don't know what I'm doing wrong. Appreciate your help.

SR_07282020_01.pngSR_07282020_02.pngSR_07282020_03.png

PD Sheehan
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 Champions.
July 28, 2020

Looks like your custom field is a Multi User Picker. From the earlier discussion, I was assuming a single user picker and shows a corresponding example.

For multi user picker, you must do it like this:

def customerAssigneeFormField = getFieldById('customField_10402')
customerAssigneeFormField.setFormValue([custAssignee])
Like Shah Baloch likes this
Shah Baloch
Contributor
July 28, 2020

My apology, I just used an exiting one and didn't realize that can be an issue. I tried the above method, but it is still didn't. I create a new custom field (User Picker (customFieldId=16200)) but for some reason it won't work if I use "getFieldById". I changed it to "getFieldByName then work. Why it is not working with Field id?

PD Sheehan
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 Champions.
July 28, 2020

Ah sorry my mistake... this should work (lowercase f in customfield)

def customerAssigneeFormField = getFieldById('customfield_10402')
Like Shah Baloch likes this
Shah Baloch
Contributor
July 30, 2020

Thank you so much that works.

One more question if I wanna add one more component "Support", how I can make it work? I mean right now I'm just assigning "Product" component to another user and rest of the components are getting assign to the default assignee. If I want to assign "Support" to another user, how I can make it works?

This is how wanna make it works, "dthompson" is default assignee, "cvigil" is assignee of Product and "sbaloch" for Support. I tried to copy paste the If statement and changed component and assignee but didn't work. Is it possible to accomplish that?

Above mentioned code is working fine and I just want to assign Support component to another user.

Appreciate your help.

Shah Baloch
Contributor
July 30, 2020

I tried this, but didn't work.

 

import com.atlassian.jira.bc.project.component.ProjectComponent
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
@BaseScript FieldBehaviours fieldBehaviours

def custAssignee = 'dthompson'
def components = getFieldById(getFieldChanged()).value as List<ProjectComponent>
if(components.any{it.name == 'Product'}){
custAssignee = 'cvigil'
}
if(components.any{it.name == 'Support'}){ 
custAssignee = 'sbaloch' 
}

def customerAssigneeFormField = getFieldById('customfield_10401')
customerAssigneeFormField.setFormValue(custAssignee)

 

Thanks

PD Sheehan
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 Champions.
July 30, 2020

I see nothing wrong with this code.
What doesn't work? Are you seeing any errors in altassian-jira.log?

Like Shah Baloch likes this
Shah Baloch
Contributor
July 30, 2020

Thank you I think I was missing something, I tried it with another user and it works. Thank you so much.

TAGS
AUG Leaders

Atlassian Community Events