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

Behavior to retrieve the reporter of the Request on the Portal

C_ Derek Fields
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 Leaders.
March 22, 2023

I have Request Type where I want to set the values of certain fields based on the reporter. This all works fine if I assume that the logged-in user is the Reporter. However, if a Service Desk Agent selects a different user from the "Raise this request on behalf of" field, I want to capture that value and use it to populate the fields on the Request.

Is there a way using a ScriptRunner behavior to get the value of the "Raise this request on behalf of" field?

 

UPDATE WITH SOLUTION: The "Raise this request on behalf of" field can be retrieved and managed as getFieldByName("Reporter")

3 answers

1 accepted

3 votes
Answer accepted
Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2023

Hi @C_ Derek Fields

To answer your question, Behaviour will not be the best solution for this scenario. It would be better to use the Post-Function instead, i.e. for the Create transition.

Also, it would be best to upgrade your ScriptRunner plugin to the latest release, i.e. 7.13.0 and use the HAPI feature, which simplifies much of the coding.

Below is a sample working HAPI code for your reference:-

Issues.getByKey(issue.key).update {
setCustomFieldValue('Sample Text Field', issue.reporter.displayName)
}

Please note that the sample working code above is not 100% exact to your environment. Hence, you will need to make the required modifications.

Below are a couple of screenshots of the Post-Function configuration.

1. In this example, the Create transition adds the Post-Function.

image_2023-03-23_170148045.png

 

2. The Custom script Post-Function is used as shown in the screenshot below:-

custom_post_function1.png

3. The Custom script post-function view:-

view1.png

 

Below are a couple of test screenshots for your reference:-

1. First, I am creating a Technical Support ticket.

test1.png

2. Currently, the Raise this request on behalf is set to the user I have logged in as

test2.png

 

3. I updated the Raise this request on behalf of the field to Max Peterson and filled in the Summary and Description. Currently, the Sample Text Field is empty

test3.png

4. Once the ticket is created as expected, the Sample Text Field value is set to the reporter, i.e. Max Peterson and not the logged-in user.

test4.png

 

 

I hope this helps to answer your question. :-)

Thank you and Kind regards,
Ram

 

C_ Derek Fields
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 Leaders.
March 23, 2023

@Ram Kumar Aravindakshan _Adaptavist_ I appreciate the answer. However, I want to pre-populate the fields with current information on the form so that the user can then change the values that they want to change when they create the ticket. I want the agent to see the values associated with the person that they have selected, not the values associated with themselves.

For example (not a real example, an illustration), I have a Name, Phone Number, and Date of Birth change request. I want the user to see the current values that are in the system for them before they make the change, so I pre-populate those fields on the form. They can change what needs to be changed and leave the rest of the values alone. They submit the ticket and my workflow handles the changes. In this case, I know who the user is because I can get it from the currentUser() API.

The problem is when a user calls in to the Service Desk and says "I am John Doe and you have my Date of Birth wrong". The agent opens the form. Using the currentUser() API, I fill in the ticket with the Agent's information, not John Doe's information. That is fine if, when the agent selects John Doe from the "Raise this request on behalf of" field, I can re-populate the form with John Doe's information. However, I don't seem to have a way to get the value of that field or trigger on it.

Ram Kumar Aravindakshan _Adaptavist_
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 23, 2023

Hi @C_ Derek Fields

I did a quick check with the development team they mentioned that the Raise this request on behalf of should contain the details of the user that has been set for that field.

Since it still contains the currently logged-in user's details, it seems to be a Bug.

I suggest that you raise a Bug ticket in the Adaptavist support portal.

Thank you and Kind regards,
Ram

C_ Derek Fields
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 Leaders.
March 23, 2023

@Ram Kumar Aravindakshan _Adaptavist_You answered my question, which is that it isn't a bug. I just wasn't retrieving the field correctly. Once I changed my script to retrieve the field as "Reporter", it worked as expected. Maybe worth adding that to the documentation somewhere? Or maybe I missed it?

1 vote
Trang Ngoc Nguyen December 4, 2023

Just want to note here for those who are finding the answer that, if you want to for example populate value for a user picker customfield_XXX on the request type form depending on the value of the user who is in the field "Raise this request on behalf of", you need to:

  1. Add a behaviour
  2. Add mapping using "Service desk mapping"
  3. Add the field "Reporter" in the behaviour (it is very important this step, you need to add the script to the field that your manipulation will be dependent on)
  4. Add server-side script for the Reporter field
  5. To get the user who is in the field "Raise this request on behalf of", use e.g
def reporter = getFieldById('reporter').getFormValue()

def customField = getFieldById(XXX)

if (reporter == A) {
customField.setFormValue("${reporter}")
}

Note that I would recommend using the getFieldById instead of getFieldByName, even though Reporter is a system field. This is because if your user has another language preference in Jira, then the field name will automatically be changed to the local language version, and then your code will not work.

Hope that helps! 

1 vote
Joseph Chung Yin
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
March 22, 2023

@C_ Derek Fields -

To my knowledge when agent uses "Raise this request on behalf of" field to create a case in JSM, the field itself it is still the actual reporter field in the system.  It is not a different field.  I am surprised that ScriptRunner for Jira will behave differently.  Unless in your behavior setup, you are pulling the current logged in user information.

I would suggest that you also reach out to ScriptRunner vendor for their input on this matter.  Their support is very good on responding to issues with the add-on.

Hope this helps.

Best, Joseph Chung Yin

Jira/JSM Functional Lead, Global Technology Applications Team

Viasat Inc.

C_ Derek Fields
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 Leaders.
March 23, 2023

@Joseph Chung Yin Thank you for your answer. You are correct, that field populates the Reporter when the form is submitted and the issue is created. However, until the form is submitted, there is no Reporter. I need to know the value of that field so that I can pre-populate values before the form is submitted.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events