Hi
I need to set an Asset field value for a team in a post function. But I'm struggling to find a syntax to set the value.
Should be the asset id or guid.
where 10010 is the issue custom field
put('/rest/api/2/issue/' + issue.key )
.header('Content-Type', 'application/json')
.body(
[
fields: [
issuetype : [
id: taskType
],
"customfield_10010" : "CT-1650"
]
])
.asString().status
Hi @Tom Lister
For your requirement, you will need to use ScriptRunner's Run Script Post-Function.
Below is a template of the code for your reference:-
def issueKey = issue.key def workspaceId = '<WORKSPACE_ID>' def newObjectId = '<OBJECT_ID>' def updateMap = ['workspaceId': workspaceId,'id': "${workspaceId}:${newObjectId}", 'objectId': newObjectId] put("/rest/api/2/issue/${issueKey}") .header('Content-Type', 'application/json') .body([ 'update': [ '<ASSET_CUSTOM_FIELD_ID>' : [ [ 'set': [ updateMap ] ] ] ] ]).asString().body
Below is an example of a fully working code for your reference:-
def issueKey = issue.key def workspaceId = '50ac2477-8e26-4836-ae41-22d86f326ee4' def newObjectId = '3' def updateMap = ['workspaceId': workspaceId,'id': "${workspaceId}:${newObjectId}", 'objectId': newObjectId] put("/rest/api/2/issue/${issueKey}") .header('Content-Type', 'application/json') .body([ 'update': [ 'customfield_10043' : [ [ 'set': [ updateMap ] ] ] ] ]).asString().body
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 screenshots of the configuration:-
1. First, Add a post function as shown in the screenshot below:-
2. From the options provided, select ScriptRunner Post-Function as shown in the screenshot below:-
3. Next, select the Run Script option as shown in the screenshot below:-
4. Once you are on the Run Script page, add the sample script template to the Additional Code section, as shown in the screenshot below:-
Once you have modified the code accordingly, update it and publish your changes.
I am also including a couple of test screenshots for your reference:-
1. Create an issue if you don't have an issue already created. Don't set any value for the Assets field as shown in the screenshot below:-
2. Once the issue is created, the Assets field is displayed in the More Fields section, as shown in the screenshot below:-
3. Next, transition the issue to the Status in which Post-Function is added. The Post-Function has been added to the Start Progress transition in this example.
4. If there is any transition screen, set the values accordingly. The screenshot below includes only the Assignee and Comment fields in the transition screen.
5. Once the issue has transitioned, the Asset field is updated accordingly and is moved to the Details section as shown in the screenshot below.
Note: You may need to refresh your page once or twice to see the Asset field update take effect.
I hope this helps to solve your question. :-)
Thank you and Kind regards,
Ram
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.