Hi Team,
Wanted to return no of weeks in the field through script.
Script is working fine and giving an output but not in the rounded form.
e.g. no of weeks should count as = 4 weeks but coming up as 4.129.
How to get the round up value from the script,
Kindly suggest.
Regards,
Neeta Jain
Hi @neeta jain
are you talking about a groovy script?
I am using scriptrunner to implement it in JIRA , below is my script:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_18880');
def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_12110');
if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date
def diffdate = dateValue - dateValue2
def noofweeks = diffdate/7
return noofweeks
}
so output of noofweeks comes as 4.429 where I need to round up to 4.
How do I do that?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @neeta jain
double noofweeks = diffdate/7
double roundNoOfWeeks = Math.round(noofweeks)
That should round to 4.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thanks Gustavo for your help.
Thank you so much again, it worked.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Your welcome.
Can you put the answer as accepted? That way people could see the question was answered.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Accepted the answer.
One small query I have.
There are certain issues already available and script is written later on.
So Do we get the the script field for exiting issues as well?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I did a test adding an scripted field to my project and all the issues created before the scripted field had a value.
So , I'm guessing the moment you add your scripfield to your screen the issues created before get the value.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi,
You are right, I can also see the scripted field for all existing issues.
Thanks again for your help.
Regards,
Neeta Jain
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Gustavo,
The script is working fine and output is coming as expected.
But when I configure this field to easyBI plugin, at the time of importing issues, it gives an error where Number Of weeks(Calculated)=0.
Do we need to declare the field as different type, below is the script for your reference.
Kindly suggest the answer:
import com.atlassian.jira.component.ComponentAccessor;
import com.atlassian.jira.issue.Issue;
import java.util.Date.*
def customFieldManager = ComponentAccessor.getCustomFieldManager();
def dateFieldObject= customFieldManager.getCustomFieldObject('customfield_18880');
def dateFieldObject2= customFieldManager.getCustomFieldObject('customfield_12110');
if(issue.getCustomFieldValue(dateFieldObject) && issue.getCustomFieldValue(dateFieldObject2)) {
def dateValue= issue.getCustomFieldValue(dateFieldObject) as Date
def dateValue2= issue.getCustomFieldValue(dateFieldObject2) as Date
def diffdate = dateValue - dateValue2
double noofweeks = diffdate/7
double roundNoOfWeeks = Math.round(noofweeks)
return roundNoOfWeeks
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neeta , I've never used eazybi but I found this that could help you.
https://docs.eazybi.com/eazybijira/data-import/data-from-jira-and-apps/jira-calculated-and-scripted-custom-fields
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @neeta jain ,
to import your field in eazyBI, you need to add this code to eazyBI advanced settings or ask Jira admin to do it (as only they have access to eazyBI advanced settings).
This code will allow eazyBI to recognize this customfield as a measure, further you need to select the custom field for import in eazyBI source data import.
[jira.customfield_NNNNN]
data_type = "integer"
dimension = true
More examples on how to import Scripted fields you will find in the link @Gustavo Félix shared.
best,
Gerda // support@eazyBI.com
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.