Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Set Form Value for Time Spent in Log Work

Burak Kaya
Contributor
February 25, 2021

Hi Folks,

I would like set a default value for Time Spent field by setFormValue function by using behaviour.

I've tried the code below but it does not work properly. Is there any suggestion?

import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.issue.fields.CustomField;
import com.atlassian.jira.issue.CustomFieldManager;
import com.onresolve.jira.groovy.user.FieldBehaviours;
import com.atlassian.jira.issue.Issue;
import groovy.transform.BaseScript

import org.apache.log4j.Level
import org.apache.log4j.Logger

@BaseScript FieldBehaviours fieldBehaviours

String className = "tr.com.as.behaviour.OysmSetTimeSpent10Min";
Logger logger = Logger.getLogger(className);
logger.setLevel(Level.ERROR);
logger.debug ("Script " + className + " started");

def timeSpent = getFieldByName("Time Spent");

timeSpent.setFormValue("10m");

Jira Version: 8.5.4
Script Runner Version: 6.19.0

Kind Regards,
Burak

2 answers

Suggest an answer

Log in or Sign up to answer
2 votes
Jimmy Seddon
Community Champion
April 10, 2020

Hi @Jae Hoon Koon _Jae Hoon Lim_,

Welcome to the community!

I will start by admitting that I'm by no means an expert when it comes to behaviours, however in an effort to try and find you an answer to this question, I dug into Adaptavist's documentation and found this:

https://scriptrunner.adaptavist.com/latest/jira/recipes/behaviours/scripted-conditions.html

It appears that you can write groovy script as your condition which in theory should allow you to write the same contents of what would be a JQL query.

I'm not sure if this will work for your particular use case, but it might be worth taking a look.

I hope that helps!

-Jimmy

1 vote
scott_boisvert
Community Champion
April 10, 2020

Could you be a little more specific in what you mean by 8sing JQL in Behaviours?  You can apply conditions based on fields similar to JQL.

Could you provide a use case of what you are trying to do?

Jagruti Mhetre
July 17, 2020

Hi , 

Even I have the same concern where I am using Time to SLA for Jira  Plugin and ScriptRunner Plugin. 

Suppose I have SLA set - In Progress -> Review  ( SLA will start In Progress status and 

will be met in Review status )

My use case is I want comment to  be mandatory if SLA is breached for transitioning In Progress to Review  , so can we use scriptrunner behaviour feature ( applying jql condition ) 

Tuncay Senturk _Snapbytes_
Community Champion
July 18, 2020

Hello @Jagruti Mhetre 

I do not know much about using JQL in Behaviours but you can use slaFunction = isBreached() to achieve that.

More info here.

TAGS
AUG Leaders

Atlassian Community Events