Hi Team,
I am working on scriptrunner on JSM data center.
I am looking for a Scriptrunner script to validate difference between start and end time is not more than 3 months
Please advise.
Thanks
Hi @Minu Murali,
You can get difference b/w 2 days by normal subtraction
endDate - startDate
or you can use below method too
//assume you fetched start and end dates already
startDate.setMonth(startDate.getMonth() + 3)
if(endDate > startDate){
//end date is 3 months greater than start Date
}else{
// end date is less than 3 months
}
hope this helps
BR,
Leo
Hi ,
I have to add one more condition to the above snippet which is to ignore a particular request type.
When I combine this condition with the above condition, it is not working.Both of them are working successfully if added separately.
import com.atlassian.jira.component.ComponentAccessor
def cfm = ComponentAccessor.getCustomFieldManager()
def start = issue.getCustomFieldValue(cfm.getCustomFieldObjectsByName("Start Date")[0])
def end = issue.getCustomFieldValue(cfm.getCustomFieldObjectsByName("End Date")[0])
def cf = ComponentAccessor.customFieldManager.getCustomFieldObjectByName("Customer Request Type")
def requestType = issue.getCustomFieldValue(cf)
start.setMonth(start.getMonth() + 3)
if ((requestType.toString != “ims/b3270e4e-6b55-4e59-b58e-8d2720a10905”) && (end > start)){
return false
}else{
return true
}
Could you please tell me why this is not working?
The expected result is if the request type is equal to the given one, it should go to else and return true.
But it still goes to check the start and end condition. ( we do not have start and end dates in this request type form)
Thanks!
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Leo,
Thanks for the prompt reply. I am fairly new to ScriptRunner so I am having difficulties.
I tried the above script but do not understand what to change where?
I managed to get this working almost 90%.
cfValues["End Date"] - cfValues ["Start Date"] <=3
is what I am using. However the 3 is defaulting to 3 days. How do I make it 3 months. ( and both my custom fields are Date and Time fields).
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
you may need to add couple of lines to include given mechanism. can you try below snippet
import com.atlassian.jira.component.ComponentAccessor
def cfm = ComponentAccessor.getCustomFieldManager()
def start = issue.getCustomFieldValue(cfm.getCustomFieldObjectsByName("Start Date")[0])
def end = issue.getCustomFieldValue(cfm.getCustomFieldObjectsByName("End Date")[0])
start.setMonth(start.getMonth() + 3)
if(end > start){
return false
}else{
return true
}
BR,
Leo
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.
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.