Want to add a "Custom scheduled job"

Manzoor Alam November 16, 2020

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