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

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

Asha Kumari September 19, 2018

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

Suggest an answer

Log in or Sign up to answer
2 votes
Answer accepted
Kristian Walker _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.
September 26, 2018

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

Asha Kumari September 27, 2018

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 :)

0 votes
Daniel Yelamos [Adaptavist]
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.
September 24, 2018

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

Asha Kumari September 24, 2018

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.

Asha Kumari September 25, 2018

jira_script_listener_import_error.png

This is the error I keep getting for any library import

Daniel Yelamos [Adaptavist]
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.
September 25, 2018

Hi Asha. 

Where it is that you are calling this script?

Cheers!

DY

Asha Kumari September 25, 2018

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

 

Daniel Yelamos [Adaptavist]
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.
September 26, 2018

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

Asha Kumari September 26, 2018

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.

Kristian Walker _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.
September 26, 2018

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

Asha Kumari September 26, 2018

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.

Kristian Walker _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.
September 26, 2018

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

Asha Kumari September 26, 2018

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.

Asha Kumari September 26, 2018

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 :)

Kristian Walker _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.
September 26, 2018

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

Asha Kumari September 26, 2018

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?

Kristian Walker _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.
September 26, 2018

I have re added this as an answer below.

Regards,

Kristian

0 votes
Asha Kumari September 23, 2018

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.

TAGS
AUG Leaders

Atlassian Community Events