I don't get any errors on the ScriptRunner console, but the date on the custom field does not get updated. Please help
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def dateCf = customFieldManager.getCustomFieldObject("customfield_12112")
def mutableIssue = ComponentAccessor.getIssueManager().getIssueObject("ABC-123")
def updated = mutableIssue.getUpdated()
mutableIssue.setCustomFieldValue(dateCf, new Timestamp((new Date() - 7).time))
mutableIssue.setUpdated(updated)
mutableIssue.store()
try like this
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
import com.atlassian.jira.event.type.EventDispatchOption
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def dateCf = customFieldManager.getCustomFieldObject("customfield_12112")
def mutableIssue = ComponentAccessor.getIssueManager().getIssueObject("ABC-123")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def updated = mutableIssue.getUpdated()
mutableIssue.setCustomFieldValue(dateCf, new Timestamp((new Date() - 7).time))
mutableIssue.setUpdated(updated)
mutableIssue.store()
ComponentAccessor.getIssueManager().updateIssue(user, issue, EventDispatchOption.ISSUE_UPDATED, false)
The function will be like that:
def findIssues(String jqlQuery) {
def issueManager = ComponentAccessor.issueManager
def user = ComponentAccessor.jiraAuthenticationContext.user
def jqlQueryParser = ComponentAccessor.getComponent(JqlQueryParser.class)
def searchProvider = ComponentAccessor.getComponent(SearchProvider.class)
def query = jqlQueryParser.parseQuery(jqlQuery)
def results = searchProvider.search(query, user, PagerFilter.unlimitedFilter)
results.issues.collect
{ issue -> issueManager.getIssueObject(issue.id) }
}
Then you ca use it like this
def query = jqlQueryParser.parseQuery(jqlQuery)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Can you help me fix the following? I am running this through ScriptRunner console. I am updating a text field but do not want to change the Updated date/time. It updates the text field but also updates the last update time.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
import com.atlassian.jira.event.type.EventDispatchOption
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def name = customFieldManager.getCustomFieldObject("customfield_10217")
def mutableIssue = ComponentAccessor.getIssueManager().getIssueObject("ABC-123")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def updated = mutableIssue.getUpdated()
mutableIssue.setCustomFieldValue(name, "John")
mutableIssue.setUpdated(updated)
mutableIssue.store()
ComponentAccessor.getIssueManager().updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I do not understand exactly what you mean. First of all, if you update an issue with
ComponentAccessor.getIssueManager().updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
Then Jira will automatically change the update time of the issue. I guess, you do not want it. Then you have to change it back to the time you want. Then your script would look like this.
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.CustomFieldManager
import com.atlassian.jira.issue.MutableIssue
import java.sql.Timestamp
import com.atlassian.jira.event.type.EventDispatchOption
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def name = customFieldManager.getCustomFieldObject("customfield_10217")
def mutableIssue = ComponentAccessor.getIssueManager().getIssueObject("ABC-123")
def user = ComponentAccessor.getJiraAuthenticationContext().getLoggedInUser()
def updated = mutableIssue.getUpdated()
mutableIssue.setCustomFieldValue(name, "John")
ComponentAccessor.getIssueManager().updateIssue(user, mutableIssue, EventDispatchOption.ISSUE_UPDATED, false)
mutableIssue.setUpdated(updated)
mutableIssue.store()
I am not sure, if I understood your question correctly. Such manipulation seems odd, because I have never met such a requirement before. Moreover, if you have an audit division at work, which checks the history of each issue, you could have problems with what you do, because you are changing the history of an issue. Update time in your case.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.