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

How to hide button of transition if Customer Request Type = Value ?

Pavel Rusakov February 8, 2022

Hello everyone! I have a workflow with some transition and many types of queries for this WF. But I want to hide the transition for some request type. How can i do this?

Maybe i can use "Custom script condition [ScriptRunner]" ?
Enybody can show exapmle?

3 answers

1 accepted

2 votes
Answer accepted
Pavel Rusakov February 9, 2022

Thanks to all!

I used Simple Script Condition with code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.IssueManager
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def requestTypeCf = customFieldManager.getCustomFieldObject("customfield_your CF ID") issue.getCustomFieldValue(requestTypeCf).value ! = "ID of your Request Type"

Works great for me!

Brent Nye January 12, 2024

This seems to be the cleanest, easiest solution. Thank you!

Note that "ID of your Request Type" can be found a couple ways. Easiest is probably to export an issue with the desired Customer Request Type to XML, then searching for "customer request type."

Like Pavel Rusakov likes this
2 votes
Fabio Racobaldo _Herzum_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2022

Hi @Pavel Rusakov ,

you are right! You can use Custom scripted condition provided by script runner.

Here an example.

Custom Field = TEXT

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.fields.CustomField;


CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = customFieldManager.getCustomFieldObjectByName("YOUR_CUSTOM_FIELD_HERE");

String cfValue = issue.getCustomFieldValue(cf)!=null?issue.getCustomFieldValue(cf).toString():null;
if("YOUR_CF_VALUE_HERE".equalsIgnoreCase(cfValue)){
return false;
}
return true;

Custom Fied = SelectList

import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.CustomFieldManager;
import com.atlassian.jira.issue.Issue;
import com.atlassian.jira.issue.customfields.option.Option;
import com.atlassian.jira.issue.fields.CustomField;

CustomFieldManager customFieldManager = ComponentAccessor.getCustomFieldManager();
CustomField cf = customFieldManager.getCustomFieldObjectByName("YOUR_CUSTOM_FIELD_HERE");

String cfValue = issue.getCustomFieldValue(cf)!=null?((Option)issue.getCustomFieldValue(cf)).getValue():null;
if("YOUR_CF_VALUE_HERE".equalsIgnoreCase(cfValue)){
return false;
}
return true;

 

Hope this helps,

Fabio

1 vote
Tuncay Senturk
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
February 9, 2022

Hi @Pavel Rusakov 

You can use custom script condition.

And below is the script getting the request type of the issue and checking with the one you want. Place user accordingly.

I hope it helps

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.servicedesk.api.requesttype.RequestTypeService
import com.onresolve.scriptrunner.runner.customisers.WithPlugin

@WithPlugin("com.atlassian.servicedesk")

def requestTypeService = ComponentAccessor.getOSGiComponentInstanceOfType(RequestTypeService)

def reqQuery = requestTypeService.newQueryBuilder().issue(issue.id).build()
def reqT = requestTypeService.getRequestTypes(user, reqQuery)
def requestTypeName = reqT.getResults()[0].getName()

if("YOUR_REQ_TYPE_NAME_HERE".equalsIgnoreCase(requestTypeName)){
return false;
}
return true

 I haven't tested the code, but I think it would help. Let me know if you have any issues.

Tuncay

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events