Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

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

Field 'customfield_10406' cannot be set. It is not on the appropriate screen, or unknown Edited

I am using the Scriptrunner listener capability of Jira cloud version to update a field called 'Urgency' based on the value of the field 'Severity'. This is for a servicedesk project.

I checked the screens (actually there is only 1 screen for create, view, edit) and the screen has both of these fields. Yet, I am not able to update the field value and it keeps giving me the above error. I am running the script as a "ScriptRunner Add-On User"

Could someone please help me to point out where the problem is and how can I address this?

Roughly, this is how my script looks:

def projectKey = "PS"

def issueKey = issue.key
def issueType = ((Map)issue.fields.issuetype).name as String

if (issueType == null || issueType != "Bug") {
logger.info("Wrong Issue Type ${issueType}")
return
}

def fields = issue.fields as Map
def severityField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Severity'
} as Map

def severityValue = (fields[severityField.id] as Map).value as String
def urgencyValue = "" as String


if (severityValue == "A" || severityValue == "B") {
urgencyValue = "Critical"
} else if (severityValue == "C") {
urgencyValue = "High"
} else if (severityValue == "D") {
urgencyValue = "Medium"
} else {
urgencyValue = "Low"
}


def urgencyField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Urgency'
} as Map

def result = put("/rest/api/2/issue/${issueKey}")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
"{$urgencyField.key}": [
value: "${urgencyValue}"
]
]
])
.asString()

if (result.status == 204) {
return 'Success'
} else {
return "${result.status}: ${result.body}"
}


 

3 answers

1 accepted

2 votes
Answer accepted

Hi Asha,

Thank you for confirming this.

I can confirm that to set the value for a field which is not on screen that you will need to override the overrideScreenSecurity query paramater in the Rest call where you are setting the field and this will require the Script Listiner to be ran as the ScriptRunner Add On user. 

We have an example of how to set this paramter inside of our documentation example which is located here and you can use this as a reference for how to set this paramater. 

If this does not resolve the issue could you please try setting  the select list value using the syntax shown in the example code snippet located here.

This example can be ran on the Script Console and shows how you can update an issue and set a select list value on an issue.

You will be able to use this example in order to modify your script to set the select list field that you require.

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

Kristian,

Thank you very much for sharing the code snippet. While my code was almost same as the one recommended by the piece of code block you shared, comparing the two blocks of code side by side, helped me find one logical error I had in my code.

This is all the problem was:

fields: [
"{$urgencyField.key}": [
value: "${urgencyValue}"
]
]

had to be changed to:

fields: [
"${urgencyField.key}": [
value: "${urgencyValue}"
]
]

 

Now it is working absolutely fine. Thank you for all your help to get me here :)

Can someone please help on this? I am stuck with this and not been able to make progress. Tried a lot of suggestions on this forum and none has helped so far.

Hi Asha.

Is there any particular reason why you are sending REST request instead of using the class methods? I haven't setup this particular example but this:

def severityField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Severity'
} as Map

Can be done like this:

import com.atlassian.jira.component.ComponentAccessor
def
severityField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Severity")

----

This:

def urgencyField = get("/rest/api/2/field")
.asObject(List)
.body
.find {
(it as Map).name == 'Urgency'
} as Map

Can be done like this:

import com.atlassian.jira.component.ComponentAccessor
def urgencyField = ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("Urgency")

----

And this, which I suppose is a customField setter of an issue value:

def result = put("/rest/api/2/issue/${issueKey}")
.queryString("overrideScreenSecurity", Boolean.TRUE)
.header('Content-Type', 'application/json')
.body([
fields: [
"{$urgencyField.key}": [
value: "${urgencyValue}"
]
]
])
.asString()

Can be done like this:

issue.setCustomFieldValue(urgencyField, urgencyValue)
def issueManager = ComponentAccessor.getIssueManager()
def user = ComponentAccessor.jiraAuthenticationContext.getLoggedInUser()

issueManager.updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)

----

Have you tried any of these?

Cheers!

DY

For whatever reason, I am not able to import the libraries like this in my script:

import com.atlassian.jira.component.ComponentAccessor

 

It keeps giving me error no matter which library I am trying to import. I tried a lot and then decided to keep it simple using APIs that probably allows me to do everything required. Haven't been successful either way though.

jira_script_listener_import_error.png

This is the error I keep getting for any library import

Hi Asha. 

Where it is that you are calling this script?

Cheers!

DY

I have tried this in 2 modes and both have same problem:

  1. Post script on status change (this actually is not the right place for me to plug in but I have tried this as well)
  2. Script listener which is configured to be triggered for a specific project on 'Issue Updated' event.

Screenshot for the reference

script_listener.PNG

 

Hi Asha.

I would like to extend my apologies. I didn't see the jira-cloud tag in the post, you don't mention that this is for Scriptrunner Cloud in the description of your question. That led me to believe this was for Jira Server. my previous comments were misleading and sadly, I have no experience with Jira Cloud, so I can't help you there.

I'm so very sorry, your original script is possibly right. 

Maybe someone that knows Cloud can help you out. 

Once again, apologies.

DYelamos

No problem Daniel. Thank you for your attempt. I also updated the issue description to call out that I am using cloud version. Hope someone helps me out with this.

Hi Asha,

I can confirm that to set the value for a field which is not on screen that you will need to override the overrideScreenSecurity query paramater in the Rest call where you are setting the field and this will require the Script Listiner to be ran as the ScriptRunner Add On user. 

We have an example of how to set this paramter inside of our documentation example which is located here and you can use this as a reference for how to set this paramater. 

Also can I please ask what type of field is customfield_10406 so that we can verify that you are specifying the correct syntax to set the field as this error could also be caused if the script cannot recognise the field and how to set it. 

Regards,

Kristian

Hi Kristian,

Thanks for trying to help on this. customfield_10406 is of select list type. The field from which I am deriving the value is also of the same type.

Hi Asha,

Thank you for confirming this.

Can you please confirm if overriding the screen  security query paramater resolves the issue and allows the field to be set. 

If this does not resolve the issue could you please try setting  the select list value using the syntax shown in the example code snippet located here.

This example can be ran on the Script Console and shows how you can update an issue and set a select list value on an issue.

You will be able to use this example in order to modify your script to set the select list field that you require.

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

Kristian,

If you noticed the code block I have shared, override screen security parameter is already set but that hasn't helped the situation. Let me try the other code snippet you have shared and get back to you on how things go.

Kristian,

Thank you very much for sharing the code snippet. While my code was almost same as the one recommended by the piece of code block you shared, comparing the two blocks of code side by side, helped me find one logical error I had in my code.

This is all the problem was:

fields: [
"{$urgencyField.key}": [
value: "${urgencyValue}"
]
]

had to be changed to:

fields: [
"${urgencyField.key}": [
value: "${urgencyValue}"
]
]

 

Now it is working absolutely fine. Thank you for all your help to get me here :)

Hi Asha,

Thank you for confirming that the issue has been resolved.

Could you please accept this answer to mark it as correct and help others find it who are searching for a similar question in future.

Regards,

Kristian

Kristian,

I am not able to do so for the specific comment that you have made. I am guessing the reason is because this is a comment under another comment and it doesn't make sense to mark that as accepted answer. Would you mind adding a separate comment with the same information provided earlier, so that I can flag that as the answer?

I have re added this as an answer below.

Regards,

Kristian

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Published in Marketplace Apps & Integrations

Why everyone using Jira must be GDPR-compliant

Did you know that penalties up to 4 % of the yearly company turnover are possible in case of GDPR violations? GDPR regulations are currently mainly relevant for companies in the EU, but countries lik...

79 views 1 2
Read article

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