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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Exclude or clear custom field for a cloned issue Edited

Team,

We are using the Jira cloud environment, we have couple of custom field which we don't want to be copied when cloned using Jira in-built functionality. The only possibility I see here is using Jira script runner plugin by configuring the listner. Could anyone help me with the script? 

Environment: Jira cloud
Custom field, Single line text field

Seems cloud script runner works in a different way than the Jira server. 

Thanks,
Suresh

2 answers

1 accepted

0 votes
Answer accepted

Hi Suresh,

Thank you for your question.

I can confirm that to have a field value removed when an issue is cloned using the built-in Jira clone issue functionality with ScriptRunner for Jira Cloud that you will need to create a Script Listener and configured to fire on the Issue Link Created event. 

The script for the listener will need to check the type of the issue link that is created and if it has the link type of cloners then will need to update the cloned issue to make a put request to the Issue  rest API in order to update the fields that you want to set to have a null value. 

I have created an example script located here which you can configure as a script listener on the  Issue Link Created event in order to clear the value of the Description field and a specified Single line text field on the cloned issue.

You will then be able to use this script as a reference guide and to modify this example in order to set other fields that you want to remove the values from when the issue is cloned.

If this response has answered your question can you please mark it as accepted so that other users can see it is correct when searching for similar answers.

Regards,

Kristian

Hi Suresh,

I can confirm that I have updated my example above to show how to remove the value from a single line select list type custom field as well. 

Regards,

Kristian

Thank you for your response Kristian!

I see below static error when configured and ended in failure. IssueLink not declared.  Is there something I need to add further?

2019-09-16 23_48_18-Script Listeners - JIRA.png

Attached screenshot.

Hi Suresh,

Can I please ask you to confirm if you set your Script Listener to be configured on the IssueLink Created event as the listener will need to be configured on this event in order for the issueLink variable to be available to the script.

I can confirm that if you use the Issue Created event which is similar that you will get this static type checking warning and that you should change the event to be the  IssueLink Created event to resolve this warning.

Regards,

Kristian

Hi Kristian,

It worked like a charm!

Yes, you're correct. I configured for Issue Created which caused static type checking warning ending up in failure. Changing the Event to IssueLink Created resolved issue.

Thank you so much!

Thanks,
Suresh

Hi Kristian,

Listener works fine as intended. However, we observer that page loads earlier than the script executes. Then refresh of the page would clear these fields. Is there way to avoid loading of the page before script executes or alternate way to implement this using issuecreated event to avoid this lag.

Please advise.

Thanks,
Suresh

Hi Suresh,

Thank you for your response.

I can confirm that unfortunately, the reason the issue loads before the listener is run is due to the fact that Atlassian has designed Jira Cloud to execute in a completely asynchronous manner as described inside of our documentation pages located here and here

This, unfortunately, means that there is no way that we can avoid the issue screen loading before the script listener has run to avoid users having to refresh the screen to see the values cleared.

As explained this caused by the way that Jira Cloud is architected and as this how Atlassian make it run then there is no way to work around this limitation.

Regards,

Kristian

Hi Kristian,

I am trying to use your script but I am having the static error issue, please be advised I am using Jira on Prem therefore will the script needs to be modified ?

Hi Sayan,

Same script doesn't work with on-prem. You need to modify the script. Try below with few modifcations.

https://community.atlassian.com/t5/Jira-questions/Clearing-fields-on-cloned-issues-during-cloning-action/qaq-p/93315

Hi Sayan,

My example on this post is only for Jira Cloud and so will not work with Jira Server.

Regards,

Kristian

@Kristian Walker _Adaptavist_ 

Can you please give an example code with cleaning a number and select list single choice field types?
Thank you!

Regards

Hristina

Hi Hrinsta,

The example above should work and you should be able to just change the field type and set null for both field types to clear a number field and a single select list field.

Regards,

Kristian

Hi Hrinsta,

I can confirm I have updated the example linked above to also show how to clear number fields and single select list fields.

Regards,

Kristian

Hi,

 

Yes, noted.

Thanks!

Hi @Kristian Walker _Adaptavist_ ,

Above script does not work for the servicedesk projects in jira cloud. Can yiu please help how we can clear the value of text field for the field in ServiceDesk project?

Thanks,
Suresh

Hi Suresh,

Can I please ask when you run the script on a Service Desk Project are you updating the issue inside of Jira or via the service desk customer portal?

If it is via the customer portal, then I can confirm that it is not possible to run a listener to clear values based on actions in the customer portal.

If you are updating the project from inside of Jira and getting errors then can you please attach a screenshot showing how the listener is configured and what error you see when you run it?

I can confirm I have tested the script on a service desk project and can confirm it will work as expected if you configure it on the *issuelink Created* event and trigger it using the built-in clone issue function inside of Jira as shown below.

Screenshot 2021-01-18 at 15.55.07.png

This means that the script is correct and the reason it is not working in your instance is due to the fact it has not been configured correctly or triggered correctly.

Regards,
Kristian

Hi Kristian,

Yes, you're correct. It is configured correctly however we are passing two fields to clear the values simultaneously. Since, the other field failes whole script terminates with failure. Thank you for the quick response.

Thanks,
Suresh

Hi Suresh,

This indicates you have not configured the script correctly on your instance to handle the fields which you are clearing as it either is not finding the field or you have not specified the correct syntax to clear that type of field.

Can you please attach a screenshot showing how you have configured the script as well as what the error you get when you run the script is so that I can see how the script is configured and what error you are receiving as without this then I cannot advise on the error you are getting?

Regards,

Kristian

Hi Kristian,

Please find the attached screenshots & they as below:

Config - 01: Shows the projects and events its configured
Script - Its the same script you had shared earlier
History - Shows all were successful
Execution History shows some logs

Salesforce CR ID: customfield_11950

Code Drop ID - Fixed: customfield_11911

 

2021-01-18 15:24:29.016 INFO - Serializing object into 'interface java.util.List'
2021-01-18 15:24:29.071 INFO - GET /rest/api/2/field asObject Request Duration: 1002ms
2021-01-18 15:24:29.592 INFO - PUT /rest/api/2/issue/431783 asString Request Duration: 443ms
2021-01-18 15:24:29.593 WARN - PUT request to /rest/api/2/issue/431783 returned an error code: status: 400 - Bad Request
body: {"errorMessages":[],"errors":{"customfield_11911":"Field 'customfield_11911' cannot be set. It is not on the appropriate screen, or unknown."}}
2021-01-18 15:24:29.594 INFO - Serializing object into 'interface java.util.Map'
2021-01-18 15:24:29.609 ERROR - Please use the ScriptRunner user to complete this task not the Initiating User.
See https://docs.atlassian.com/jira/REST/cloud/#api/2/issue-editIssue for more information.
If you are using the ScriptRunner user then check the Field Configuration{code:xml}


How we can fix this while passing two custom fields to clear their values.

Thanks,
Sures2021-01-18 23_02_05-Script Listeners-Jira.pngConfig-01.pngHistory.pngScript.png

Hi Suresh,

I can confirm that your error shows that the custom field with the ID of customfield_11911 is not on the edit screen and due to this the value cannot be cleared as the plugin can only clear values when the field exists on the edit screen.

As the error says to make the script work for fields not on the edit screen you need to uncomment line 11 and then change the script listener to run as the ScriptRunner add on User as this will then allow it to set the value of fields which are not on the edit screen.

Regards,

Kristian

Hi Kristian,

As advised, I uncommented line 11 & choosed Add-On user. I am not finding the way to give add-on user required permission.

{"errorMaessages":["Only Connect add-on users with admin scope permission are allowed to override screen security."],"errors":{}}

How we can give this permission to ScriptRunner Add-On User? 

I do not find a way to do at global level. Can you please guide me?

Thanks,

Suresh2021-01-19 19_35_21-Script Listeners - Jira.png

Hi Suresh,

Can you please confirm that you saved the script with line 11 uncommented and the As this User box set to the ScriptRunner Add-On User.

After this all new events which trigger the listener should then be able to update the field which is not on the screen. 

If this does not work then can you please provide a screenshot showing how you have configured the script to add in these changes.

Regards,

Kristian

Hi Kristian,

Seriously, I am not sure what went wrong. Just saved the content once again & it worked.

Thanks,
Suresh

Hi Suresh,

You are welcome and I am glad that your script is now working as expected.

Have a wonderful the rest of your day,

Kristian

Like Suresh Bhandiwad likes this

By the way Field is Single line text, custom field.
Environment is Jira cloud

Suggest an answer

Log in or Sign up to answer
TAGS

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