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

Set Form Value for Time Spent in Log Work

Burak Kaya 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
0 votes
Deniz Oğuz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 28, 2021

Hi Burak,

WorklogPRO has build-in way to set values on the "Log Work Custom Field" or "Log Work Dialog".  Navigate to Administration->Scripts and add following code to "Before Worklog Dialog Display Script". 

worklogPreEntryParameters.timeSpent = "10m"

PS: This only works "Log Work Custom Field" of WorklogPRO and "Log Work Dialog" of WorklogPRO. It doesn't work for build-in time tracking field or "Log Work Dialog" of Jira itself. 

Burak Kaya February 28, 2021

Hi Deniz,

Thanks for your reply.

It works as you mentioned in "Log Work Dialog" as expected, so I want to be able to use this in a transition but not able find the field "Log Work Custom Field", there is only one field which named "Log Work" and it seems that it is belong to "System Field", so could you explain me how can I add this field into a screen and can use for only the specific transition?

Thanks,

Deniz Oğuz
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 28, 2021

It is a custom field provided by WorklogPRO. You need to add it from custom field administration screen. You can add it to any transition screen like any other custom field. 

0 votes
Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2021

Try with this:

def timeSpent = getFieldById("log-work-time-logged");

I used the chrome developer panel to see the id of the field in the edit screen 

Burak Kaya February 26, 2021

Hi Peter,

Yes I also see the ID in Inspect Element but it does not work for me.

The field in a transition screen and I use the behavior but still does not work. Any other suggestion?

Thanks,
Burak

Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 26, 2021

Not sure what else to tell you.

Have you looked at your logs? Are there any errors?

With the simplest of behavior: 

2021-02-26 14_16_36-Edit Behaviour_ test.png

I see this on my screen (have to put the "Log work" field on the screen and check the box during the transition to view the default value):

2021-02-26 14_17_29-Close Task - JIRA Dev.png

Burak Kaya February 27, 2021

Hi Peter,

I also tried with your code as below but same result for me. It still does not get 10m into the screen. (Even I've removed the mapping.)

Screen Shot 2021-02-27 at 19.20.17.png

Below is my screen. 

Screen Shot 2021-02-27 at 19.20.40.png

BTW we're using WorklogPRO plugin for logging work, so probably that's why I do not see "Log Work" checkbox on my screen.

Anyway, I see "log-work-time-logged" ID in Inspect element in Chrome.

Thanks,
Burak 

Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 27, 2021

Behaviours only work with built in jira screens (Created, Edit and Transition screens).

It doesn't work with Clone, Move or Third-party screens.

Burak Kaya February 27, 2021

This is the field “Log Work” and it is in transition screen not in 3rd party screen.

Peter-Dave Sheehan
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 27, 2021

I don't think that scriptrunner is aware of, or compatible with worglogpro custom fields. 

You would have to open an enhancement request with Adaptavist.

Like Burak Kaya likes this
Claronildo Covas
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
April 14, 2022

Dear @Burak Kaya , Would know how to set a value for Remaining Estimate ?

Regards,

Covas

TAGS
AUG Leaders

Atlassian Community Events