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

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

How to update custom field value and select more than one user in custom scheduled jobs


I need to update my custom field value for every 24 hours. So I decided to use scheduled jobs but I couldn't use update function here. It's throwing error whenever I'm trying to update the custom field value from here. Added to this, I can't select more than one user name in scheduled jobs. I expect this program should allow 5 users to run it.

Can anyone please help me out 

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.Issue
import com.atlassian.jira.issue.fields.CustomField
import java.sql.Timestamp
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.IssueManager
import com.atlassian.jira.event.issue.IssueEvent
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.ModifiedValue
import com.atlassian.jira.issue.util.DefaultIssueChangeHolder

def user = ComponentAccessor.jiraAuthenticationContext.loggedInUser
JiraServiceContext sourceUserServiceCtx = new JiraServiceContextImpl(user)
def customFieldManager = ComponentAccessor.getCustomFieldManager()

def issueManager = ComponentAccessor.getIssueManager()
def issue = event.getIssue() as MutableIssue
def event = event as IssueEvent;
def issuetype = issue.getIssueType()
def changeHolder = new DefaultIssueChangeHolder()

def now = new Timestamp(new Date().getTime())

def field = customFieldManager.getCustomFieldObjectByName("custom field name")
def fieldValue = issue.getCustomFieldValue(field)

field.updateValue(null, issue, new ModifiedValue(issue.getCustomFieldValue(field),now),changeHolder)


Thanks in advance

1 answer

0 votes

Your script is throwing errors because you have not told it to do a lot, and you have got invalid calls in it.  I think you have misunderstood the job definition as well.  A job is a block of code that runs regularly in Jira.

So the misunderstandings here seem to be

  • The single user the job is asking you to configure is who the job is going to run as.  Multiple users in there makes no sense - it needs to know who to run as when the schedule comes around.
  • A job runs independently, it's not part of an issue.  Your code is asking an "event" to tell it what issue to run against, but there is no event in a job, it is not triggered by an event, it just runs when scheduled.  (I think you've copied a chunk of a scripted listener from somewhere, which will not work in a job)
  • Your code does not try to make any changes to the issue.  You are rightly trying to work out some data, but you do not actually do anything with it.  (You have some of that in your current script.  It creates a changeholder, and it applies it to the issue, but you are not actually putting anything into the change, so it's not going to do anything)

So, I would take a step back and think through:

  • When the job runs, who should it be run as?
  • When it runs, what issue(s) should it affect?  And hence, how you're going to get them.
  • When it runs against an issue, you want to change a custom field, so you'll need to work out what you want to change it to, and put that into a change

Suggest an answer

Log in or Sign up to answer
Community showcase
Published in Jira

Admins, notify your Jira instance of system-wide changes with the new admin announcement banner

Hi All! We’re excited to share the launch of an announcement banner that lets Jira site administrators communicate directly to their users across their  Jira Cloud instance.  ...

601 views 15 18
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