Assign sub task assignee to current user

Derek Imrie May 22, 2019

Hi, I'm using scriptrunner cloud to create subtask on transition.

 

Sub task is created fine and reporter is set to current user, i also want the assignee set to current user but struggling to find anything for cloud version.

 

def response = get('/rest/api/2/myself').asObject(Map)
assert response.status == 200

def currentUsername = response.body.name
issueInput.fields.assignee = [name: currentUsername] as Map

above code has worked for someone else within the post function script but returns error for me

Varible issueInput is undeclared

1 answer

0 votes
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.
May 23, 2019

Hi Derek,

Thank you for your question. 

I can confirm that the Create Subtask transition does not have an issueInput parameter in the script context which is why you are receiving the error that you are receiving and that you should change issueInput to be subtask to set the field on the subtask. 

I have tasted your code with this change and can confirm that with this change that the subtask gets created with the assignee being set.

I can confirm that you can see all parameters available in the context for your script by clicking the Show me link next to the text which says There are parameters/variables that are automatically available for use within your script: above the code box, and would always recommending checking this to see what parameters are available to the script. 

I would also advise changing the line where you get the username to get the accountId parameter rather than the name as Atlassian is removing the name parameters from the API's as part of the GDPR changes mentioned here which means that you will need to reference users by an account ID as references by name will no longer be supported. 

If this answer has solved your issue can you please accept it in order to mark this answer as correct for users who are searching for a similar issue.

Regards,

Kristian

Derek Imrie May 23, 2019

@Kristian Walker _Adaptavist_ - I'm very new to this so thanks for the help, i'll look at that

Suggest an answer

Log in or Sign up to answer