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

How do I fetch the current Customer Request Type in Initialiser script in Behaviours?

Szymon Trocha July 16, 2019

Hi all,

I'm trying to build an Initializer script in Behaviours that when the create issue (so should work with an issue create screen) window is opened (from the customer portal) reads the current Customer Request Type and hides/shows some fields. I'm having troubles in fetching the value of Customer Reuqest Type field. So far I have the current code:

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager

def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()

def customField = customFieldManager.getCustomFieldObjectByName("Customer Request Type")
log.info("customField: " + customField)
def fieldConfig = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(fieldConfig)

log.info("options: " + options)

but at this stage it doesn't deliver any value in options when I open create issue window from customer portal:

2019-07-16 15:19:08,664 /rest/scriptrunner/behaviours/latest/jsd/jsd/validatorsByPid.json [c.o.j.groovy.user.FieldBehaviours] options: []
2019-07-16 15:19:08,663 /rest/scriptrunner/behaviours/latest/jsd/jsd/validatorsByPid.json [c.o.j.groovy.user.FieldBehaviours] customField: Customer Request Type

Any help?

3 answers

1 vote
Jacek Zarzycki October 18, 2020

Dublet

1 vote
Mazen AKIKI _Infosysta_ October 8, 2020

Hi this suggestion worked for me if (getRequestTypeName() == 'IT Help')

hope this helps

Jean-François FORGET October 8, 2020

It definitely helps.

So simple.... thanks a lot!

1 vote
Jean-François FORGET May 28, 2020

Hi,

The only way I've found is using this:

getFieldById("summary").getFieldBehaviours().properties.formContents.requestTypeId

It return the Customer Request Type ID.

I still have to write the code to retrieve the Request Type details that match this ID.

Hope this can help some other peoples and if someone have a better way, feel free to share.

JF

Jacek Zarzycki October 16, 2020

Thank you very much.
getRequestTypeName () is broken and causes a crash in the script when the logged in user to SD is a client, not an actor.
You don't even know how much trouble you saved me.

Like Jean-François FORGET likes this
Jean-François FORGET October 16, 2020

LoL @Jacek Zarzycki , thank you as well.

I switched to @Mazen AKIKI _Infosysta_  solution few days ago and didn't notice the bug you've just mentioned.

 

I definitely confirm that this:

String customerRequestTypeName = (getRequestTypeName())

Must be replaced by something like this:

import com.amundi.jira.ProjectPortal
import com.atlassian.jira.project.ProjectCategory

ProjectPortal projectPortal = new ProjectPortal(project)
String customerRequestTypeId = getFieldById("summary").getFieldBehaviours().properties.formContents.requestTypeId
String customerRequestTypeName = projectPortal.getRequestById(customerRequestTypeId.toInteger()).getName()

Note: I'm on Jira Software 8.5.6 + Jira SD 4.5.6 

Jacek Zarzycki October 18, 2020

In order for the script to work with both Jira Service Desk and Jira Core "Create" use this:

import static MyUtil.MyFunctions.RequestTypeName
/*
RequestTypeName- Is my own function
This function convert diferente values like 

"41" 
"f3a26973-8692-4537-bc92-3516469e728f"
"XXX/f3a26973-8692-4537-bc92-3516469e728f"
"New Server"

  It returns the string with the name "Request Name ABC" or ""
*/


static com.atlassian.jira.issue.IssueFieldConstants.SUMMARY
String tmpRequest = ""
String RequestTypeValue = ""

try {
  def Summary = getFieldById(SUMMARY)
  tmpRequest = Summary.getFieldBehaviours().properties.formContents.requestTypeId.toString()
}
finally {
   RequestTypeValue = RequestTypeName(tmpRequest)
}

// User does not use Service Desk but Jira Core "Create" or "Edit"
// if you try validate tmpRequest  here it want work
if ( RequestTypeValue == "") { 
   try {
       def RT = getFieldByName("Request Type")
       tmpRequest = RT.getValue().toString()
   }
   finally {
     RequestTypeValue = RequestTypeName(tmpRequest)
   }
}

if (RequestTypeValue  == "Request Name ABC" ) {
  do something ...
}

 I'm on Jira Software 8.5.4 + Jira SD 4.5.4 

Like Jean-François FORGET likes this
Jacek Zarzycki October 18, 2020

Dublet

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events