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

Next challenges

Recent achievements

  • Global
  • Personal

Recognition

  • Give kudos
  • Received
  • Given

Leaderboard

  • Global

Trophy case

Kudos (beta program)

Kudos logo

You've been invited into the Kudos (beta program) private group. Chat with others in the program, or give feedback to Atlassian.

View group

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

Want to add a "Custom scheduled job" Edited

Hi Team Atlassian,

I want to add a *Custom Schedule Job* in JIRA with the help of the Script Runner plugin.

I don't have much idea how to write a script, below are few lines of code that I have copied and did some modification to update a custom field on the basis of Baseline End Date and Current Date.

It is running as a Behaviour, but in Custom Schedule Job getting error.

Please help me to correct the below code.

{code:xml}

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.user.ApplicationUser;
import com.atlassian.jira.user.util.UserUtil;
import com.onresolve.jira.groovy.user.FieldBehaviours
import groovy.transform.BaseScript
import java.text.SimpleDateFormat;
import java.text.DateFormat

//
def customFieldManager = ComponentAccessor.getCustomFieldManager()
def optionsManager = ComponentAccessor.getOptionsManager()
def SDLCCheckPoint = getFieldById("customfield_11905")
// Get access to the required custom field and optionsmanagers
def customField = customFieldManager.getCustomFieldObject(SDLCCheckPoint.getFieldId())
def config = customField.getRelevantConfig(getIssueContext())
def options = optionsManager.getOptions(config)

Date date = new Date()
log.warn("Current date: " + date)

// Here field name "Baseline End Date"
def baselineEndDate = getFieldById("customfield_12007")
def baselineEndDateValue = baselineEndDate.getValue()
log.warn("BaselineEndDateValue: " + baselineEndDateValue)

if(baselineEndDateValue.format("yyyy-MM-dd").compareTo(date.format("yyyy-MM-dd")) >= 0) {
//def optionsMap = ["-1" : "None"]
def optionsMap1 = options.findAll {
it.value in["on Track"]
}.collectEntries {
[(it.optionId.toString()): it.value]
}
SDLCCheckPoint.setFieldOptions(optionsMap1)
SDLCCheckPoint.setReadOnly(true)
}
else if(baselineEndDateValue.format("yyyy-MM-dd").compareTo(date.format("yyyy-MM-dd")) < 0){
//def optionsMap = ["-1" : "None"]
def optionsMap2 = options.findAll {
it.value in["Late"]
}.collectEntries {
[(it.optionId.toString()): it.value]
}
SDLCCheckPoint.setFieldOptions(optionsMap2)
SDLCCheckPoint.setReadOnly(true)
}

{code}

 

Error:

{code:xml}

2020-11-17 10:26:23,260 WARN [runner.ScriptBindingsManager]: --- Begin Behaviour --- 2020-11-17 10:26:23,260 ERROR [jobs.AbstractCustomScheduledJob]: ************************************************************************************* 2020-11-17 10:26:23,260 ERROR [jobs.AbstractCustomScheduledJob]: Script job: 'Check Point Cron' failed groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getFieldById() is applicable for argument types: (String) values: [customfield_11905] at Script540.run(Script540.groovy:13)

{code}

Error

groovy.lang.MissingMethodException: No signature of method: org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.getFieldById() is applicable for argument types: (String) values: [customfield_11905] at Script540.run(Script540.groovy:13) null

 

Thanks & Regards,

Manzoor Alam

0 answers

Suggest an answer

Log in or Sign up to answer
TAGS
Community showcase
Posted in Jira Software

Presenting the "Best of 2020" Jira Software roundup!

Catch up with Atlassian Product Managers in our 2020 Demo Den round-up! From Advanced Roadmaps to Code in Jira to Next-Gen Workflows, check out the videos below to help up-level your work in the new ...

7,073 views 8 28
Join discussion

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