Hello all,
I am looking to create a custom field that will be based on create date plus days. This field will be mostly used for counting time to close based on work hours days. if an issue is created between 8:00 to 18:00 the sla should show created date plus 6 days but if it',s created between 18:00 to 8:00 it should calculate created date plus 7 date.
Example would be:
Create date=1.1.19 8:00 + 6d = 7.1.19 18:00 [it should set always a specific hour 18:00 no matter when it was created.
Created date = 1.1.19 19:00 +7d = 8.1.19 18:00
it should set the value of this addition in days and a specific hour 18:00
Any suggestions would be greatly appreciated PLEASE.
Thanks
Have a look on comment to line 8 :)
Hi,
After trying it, I noticed that in my create transition I have already built in the option of store.
See screenshot attached of your script and where I place it in my transition.
You can see also the "store" option below it.
The script still doesn't work.
Your help and advise please
Thx!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear arie, hi!
It seems that you need a custom postfuction on create trnasition to fill this date.
There are several plugins for this.
We use Script Runner.
Best regards, Vasiliy.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thank a lot
I use also scriptrunne but i m not familiar with it.
can you please help me and send me a script that i can run to get what i need as described upon?
thanks again
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is a draft,
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import java.sql.Timestamp
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("issueKey"); //commnet into postfunction. For Script console only
Calendar newDate = Calendar.getInstance();
newDate.setTime(issue.getCreated());
int addDays = 6;
if ( (newDate.get(Calendar.HOUR_OF_DAY) < 8) & (newDate.get(Calendar.HOUR_OF_DAY) > 18) )
addDays = 7;
newDate.add(Calendar.DAY_OF_YEAR, addDays);
issue.setCustomFieldValue( ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldName"), new Timestamp(newDate.getTimeInMillis()))
//Save chanes into DB. Only for script console
ComponentAccessor.getIssueManager().updateIssue(
ComponentAccessor.getJiraAuthenticationContext().getUser(),
issue,
UpdateIssueRequest.builder().sendMail(false).eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).build()
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks a lot.
i will try it.
one more thing plz that i had forgot is that i need it to skip weekend days [friday and saturday] what should i change?
thanks again for your help
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Into Calendar class you can get number on week. So, you need a while loop to get this date.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
i had just run your script in my scripted field "due date" and i get this error:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed: Script208.groovy: 25: expecting ')', found '' @ line 25, column 1. 1 error
in addition i am not familiar with scrip runner so if i should do something to make it run plz don't hesitate to write to me even if it is an obvious thing that everyone already know.
according to skip weekend can you please insert this change to your script please ?
here screenshot of my scripted field attached to this email:
thanks a lot for the help!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here is version about hilidays:
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import java.sql.Timestamp
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("issueKey"); //commnet into postfunction. For Script console only
Calendar newDate = Calendar.getInstance();
newDate.setTime(issue.getCreated());
int addDays = 6;
if ( (newDate.get(Calendar.HOUR_OF_DAY) < 8) & (newDate.get(Calendar.HOUR_OF_DAY) > 18) )
addDays = 7;
while (addDays > 0){
newDate.add(Calendar.DAY_OF_YEAR, 1);
if(newDate.get(Calendar.DAY_OF_WEEK) < Calendar.SATURDAY){
--addDays;
}
}
issue.setCustomFieldValue( ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldName"), new Timestamp(newDate.getTimeInMillis()))
//Save chanes into DB. Only for script console
ComponentAccessor.getIssueManager().updateIssue(
ComponentAccessor.getJiraAuthenticationContext().getUser(),
issue,
UpdateIssueRequest.builder().sendMail(false).eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).build()
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
THX!
After trying it i get this error:
java.lang.NullPointerException: Cannot invoke method getCreated() on null object
at Script426.run(Script426.groovy:11) :-(
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
So,
when you use this script into postfunction you have a variable "issue" which resresents current issue.
When you run it frim script console you need to create this issue manually this is 11 line for. In this case you should enter proper issue key.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thx for your answer.
I use this script into postfunction and i get that error, what am i doing wrong?
In addition i need also please that this script will give me a value with a specific time.
See for Example:
Create date=1.1.19 8:00 + 6d = 7.1.19 18:30[it should set always a specific hour 18:30no matter when it was created.
Created date = 1.1.19 19:00 +7d = 8.1.19 18:30
it should set the value of this addition in days and a specific hour 18:00
I need the result to be set at 1830.
Can please add this to the script?
Thanks again
Best regard
Arige
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here you are
import com.atlassian.jira.component.ComponentAccessor
import com.atlassian.jira.event.type.EventDispatchOption
import com.atlassian.jira.issue.MutableIssue
import com.atlassian.jira.issue.UpdateIssueRequest
import java.sql.Timestamp
MutableIssue issue = ComponentAccessor.getIssueManager().getIssueObject("issueKey"); //commnet into postfunction. For Script console only
Calendar newDate = Calendar.getInstance();
newDate.setTime(issue.getCreated());
newDate.set(Calendar.HOUR_OF_DAY, 18);
newDate.set(Calendar.MINUTE, 30);
newDate.set(Calendar.SECOND, 0);
int addDays = 6;
if ( (newDate.get(Calendar.HOUR_OF_DAY) < 8) & (newDate.get(Calendar.HOUR_OF_DAY) > 18) )
addDays = 7;
while (addDays > 0){
newDate.add(Calendar.DAY_OF_YEAR, 1);
if(newDate.get(Calendar.DAY_OF_WEEK) < Calendar.SATURDAY){
--addDays;
}
}
issue.setCustomFieldValue( ComponentAccessor.getCustomFieldManager().getCustomFieldObjectByName("fieldName"), new Timestamp(newDate.getTimeInMillis()))
//Save chanes into DB. Only for script console
ComponentAccessor.getIssueManager().updateIssue(
ComponentAccessor.getJiraAuthenticationContext().getUser(),
issue,
UpdateIssueRequest.builder().sendMail(false).eventDispatchOption(EventDispatchOption.ISSUE_UPDATED).build()
)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi
Tnx.
I run this script in my post and unfortunately it doen't present a value in my custom field but when i run it from the consol it does.
I need this script to work from my post or from a scripted field so when an issue is created my custom field will take the value as configured in my post or scripted field.
In addition after running this script in my consol i realize that the given value don 't skip friday just saturday, so i need please to add to this script to skip also friday.
Please your help
And thanks a lot for your help and patient
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
On create transition you shoul add manually build-in postfunction "Store changes into database". It always added by defautl at all transitons. but not for create transition.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
But i need a script for create transition that can calculate created date as described in my first email.
Is it possible to get a script like that please?
any suggestion that can solve my problem please?
Build in postfunction manually doesn t give the due date time for all created issue.
Please any helthx
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@אריג' חמדאן, you need to postfunctions:
first one to set date as I provided
second one to store changed values to DB. This is build-in postfunction is for.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Thx
Can you please send me screenshots so i can see where and how it should look because i don t understand where i should set values to db...
Thx again
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear @אריג' חמדאן, open you workflow, choice create transition and go to postfunction tab. You will see several postfunctions here.
To realise you requarement you should manually add two postfunctions discribed above. See this: https://confluence.atlassian.com/adminjiraserver0710/advanced-workflow-configuration-953144832.html
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
i know to do that
see screenshot below' i had set your script into inline script.
which another post i should choose from my postfunction? to set to it the second part of your script?
thx
best regard
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
This is for script postfunction and it is ok. Save it.
Open any ather postfunction and you will see in postfunction list store and reindex issue postfunctions. There no such on create transition. It means that you make changes to date filed, but not store it to DB.
So, you have to add it manually.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can't understand where and what i should add manually?
It should be done manually for every created issue?
Thx
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Dear Arige, let start once again.
Open postfunction tab on any transition and you will find a postfunction to store chages into database, exept create transiton. Lets suppose you have 5 postfunctions to change diffent custom values. If you want to have only one record into change history you should call store to DB only once.
After this open postfunction tab of create transition on any workflow. There is no store to DB postfunction. It means that any changes made by postfunctions will not be stores to DB.
So, on create transition press "Add postfunction" and choose one names like "Store changes to DB".
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Ok.
Maybe a screenshot will help me to understand what i am missing.
Thx for your patient and your help.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Another thing to clarify my case, i need this script to work just on my create transition else it won't answer my demand and i won't get my wishing calculated custum field that should be view on my created view screen.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Here you are
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.