The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

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

Groovy how to remove last char from time spent

Omprakash Thamsetty
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 Champions.
September 17, 2020

Hi,

What is the function I can use to strip last char from string/value? 

 

I am getting the value from "Time Spent" field. Users will enter time in H or week or days so I would like to get only number from it. 

Thanks,

Om

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

0 votes
Answer accepted
Ravi Sagar _Sparxsys_
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 Champions.
September 17, 2020

Hi @Omprakash Thamsetty 

You don't need to. Try this method on the issue object.

issue.getTimeSpent()

 I hope it helps.

Ravi

Omprakash Thamsetty
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 Champions.
September 17, 2020

Hi @Ravi Sagar _Sparxsys_ issue.getTimeSpent() will give us underlying issue value but I am getting the value for Time Spent from "log work" screen in behavior. So it is giving the value as 1h , if user enter 1 hour. I need to strip the H letter and get 1. 

 

Thanks,

Om

Ravi Sagar _Sparxsys_
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 Champions.
September 17, 2020

Oh ok. What about something like 

string.substring(0, string.length()-1)

Let me know. 

Omprakash Thamsetty
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 Champions.
September 17, 2020

Seeing error. Look like subString doesn't like in behavior it seems.

 

def tmspentIDfld = getFieldById("timeLogged") //during the log work screen.
def tmspentIDfldVal = tmspentIDfld.getValue()

def length = tmspentIDfldVal.substring(0, tmspentIDfldVal.length()-1)

Ravi Sagar _Sparxsys_
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 Champions.
September 17, 2020

What is the error?

Omprakash Thamsetty
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 Champions.
September 18, 2020

Hi @Ravi Sagar _Sparxsys_ I converted as string once I got the value so it fixed the error. It was some data type.

so that code was

def tmspentIDfld = getFieldById("timeLogged") //during the log work screen.
def tmspentIDfldVal = tmspentIDfld.getValue().toString()

 

def length = tmspentIDfldVal.substring(0, tmspentIDfldVal.length()-1)

Like Ravi Sagar _Sparxsys_ likes this
Ravi Sagar _Sparxsys_
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 Champions.
September 18, 2020

Great!

DEPLOYMENT TYPE
SERVER
VERSION
8.5.4
TAGS
AUG Leaders

Atlassian Community Events